Custom Logging Best Practice

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

Moderators: Lapo, Bax

balasourav
Posts: 22
Joined: 25 Jul 2017, 07:44

Custom Logging Best Practice

Postby balasourav » 03 Aug 2020, 11:56

I want a custom logs for my project, so i use the link to configure customs logs -



Step 1 - i import external jar slf4j.api-1.7.5.jar. (That is not mentioned in your document) And Do like in your Document.

Step 2 - I don't want to create log for Each java class, so create a one static class and wrote like this

Code: Select all

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class Globe
{
   public static Logger log = LoggerFactory.getLogger(Globe.class);
}

I have lots class so i decide to import the globe class, where i want to put logger like below

Code: Select all

Globe.log.info("Hello World");


I don't know lapo. this is best practice or not. I need your suggestion. I want to create the log variable only once it can work to all class. Anyone can also help with us.
User avatar
Lapo
Site Admin
Posts: 23027
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Custom Logging Best Practice

Postby Lapo » 03 Aug 2020, 15:36

I don't like the global static log object for two reasons:
1- logging is synchronized
2- one of the fields in the log data is the class that generated the message. With the global approach it will always report the same class

Cheers
Lapo
--
gotoAndPlay()
...addicted to flash games
balasourav
Posts: 22
Joined: 25 Jul 2017, 07:44

Re: Custom Logging Best Practice

Postby balasourav » 03 Aug 2020, 17:39

Lapo wrote:I don't like the global static log object for two reasons:
1- logging is synchronized
2- one of the fields in the log data is the class that generated the message. With the global approach it will always report the same class

Cheers

Thanks For Your Reply Lapo.
Ok. Please tell what can i do?. How to handle logs for big project?
User avatar
Lapo
Site Admin
Posts: 23027
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Custom Logging Best Practice

Postby Lapo » 04 Aug 2020, 05:43

Create a logger object in each class that requires it.

Cheers
Lapo

--

gotoAndPlay()

...addicted to flash games
balasourav
Posts: 22
Joined: 25 Jul 2017, 07:44

Re: Custom Logging Best Practice

Postby balasourav » 21 Aug 2020, 07:22

Lapo wrote:Create a logger object in each class that requires it.

Cheers


Done Lapo Great Response. :D

Return to “SFS2X Questions”

Who is online

Users browsing this forum: No registered users and 125 guests