I am initializing the logger in servlet's constructor. Is it a good practice? Should I rather initialize it in a servletContextListener?
Sample Code:
public class MyService{
Logger logger;
public MyService(){
logger = Logger.getLogger(MyService.class);
}
}
Use the logger as a Class level member by declaring it as static
private static final Logger logger = Logger.getLogger(*<yourclass>*.class)
I think you're talking about initializing the log4j logging system, not a specific logger.
Use servletContextListener is better than the servlet's constructor.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.