how to setup logger in client

Post here your questions about SFS2X. Here we discuss all server-side matters. For client API questions see the dedicated forums.

Moderators: Lapo, Bax

hng
Posts: 37
Joined: 01 Nov 2021, 18:17

how to setup logger in client

Postby hng » 19 Sep 2022, 04:18

How to setup build-in logger in client ?

In server simple edit the .\config\log4j.properties, where to put this file in clients apps, the clients in java apps, browser js and android apps.

I had tried follow the examples:
[url]
http://docs2x.smartfoxserver.com/api-do ... ogger.html
[/url]

Code: Select all

sfs.logger.addEventListener(SFS2X.LoggerEvent.INFO, onInfoMessage, this);


but it said logger is not found. How/where to declare sfs.logger ?


atm i add custom logj2 in maven

Code: Select all

        <dependency>
            <groupId>org.apache.logging.log4j</groupId>
            <artifactId>log4j-api</artifactId>
            <version>2.16.0</version>
        </dependency>


but this only log my custom error/info since I cannot attach the new log2j into current build in sfs log

some help please
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: how to setup logger in client

Postby Lapo » 19 Sep 2022, 07:09

Hi,
you have linked a page of our Javascript documentation but you're referring to Java tools and libraries such as maven and log4J2... so what is the client technology you're using?

The Java API come with a basic logger which is the "Simple logger" implementation provided by SFL4J. You could replace that by using the standard Java logging library or Log4J and configuring it before starting the SFS client.

Under Android the logging system is already provided by the OS, so you just need to learn how to use it.

As regards HTML/JS, Javascript doesn't really allow to write log files from a browser app. You can still log messages to the browser's console fore debugging purposes but those messages will be lost when the page is closed.

Cheers
Lapo
--
gotoAndPlay()
...addicted to flash games
hng
Posts: 37
Joined: 01 Nov 2021, 18:17

Re: how to setup logger in client

Postby hng » 19 Sep 2022, 10:51

we have 3 clients (Java, Html/Js and Android) at the moments.

so the code :

Code: Select all

   sfs.logger.addEventListener(SFS2X.LoggerEvent.INFO, onInfoMessage, this);


is for JS only yes ? This is not intended for Java and Android Clients ?
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: how to setup logger in client

Postby Lapo » 19 Sep 2022, 13:23

Hi,
the line of code you have posted allows you to catch the API messages that would normally be sent to the browser's console so you can redirect them elsewhere.

I've checked the Java API and it looks like this type of event is not supported there, though I am not sure why. I'll investigate with my colleagues and if possible make sure this is introduced in our next release, for consistency's sake.

Cheers
Lapo

--

gotoAndPlay()

...addicted to flash games
hng
Posts: 37
Joined: 01 Nov 2021, 18:17

Re: how to setup logger in client

Postby hng » 20 Sep 2022, 07:29

Thank you very much Lapo
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: how to setup logger in client

Postby Lapo » 23 Sep 2022, 07:30

As regards the difference between Java and other API (C#, Javascript) in terms of logging: in Java we used an existing and popular framework called SLF4J (https://www.slf4j.org/) which is a logging abstraction, allowing to plugin your favorite logging libraries.

In other languages such as C# and JS we instead implemented our own logging solution, which includes an event system allowing to receive an event every time the API log a message.

In the end we decided not to roll out our own implementation in Java and use SLF4J because it's very popular among Java devs and allows for lots of customization. Hence the discrepancy among different API.

Hope it helps
Lapo

--

gotoAndPlay()

...addicted to flash games

Return to “SFS2X Questions”

Who is online

Users browsing this forum: No registered users and 44 guests