In each class I have logger that is used for logging:
public class Myclass
{
public final Logger log = Logger.getLogger(getClass());
}
But what to do when I need to log static methods? log
is not static variable?
Loggers should be declared to be static and final. It is good programming practice to share a single logger object between all of the instances of a particular class and to use the same logger for the duration of the program.
log4j is a reliable, fast and flexible logging framework (APIs) written in Java, which is distributed under the Apache Software License. log4j is a popular logging package written in Java. log4j has been ported to the C, C++, C#, Perl, Python, Ruby, and Eiffel languages.
Make your logger static:
public class Myclass
{
private static final Logger log = Logger.getLogger(Myclass.class);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With