It is clear that the question is a little "bad", but still … How do you implement (consider it correct to implement) logging in servlets. Those. given
log4j; the task is to implement logging. The question is: what is the correct way (taking into account the overhead of creating objects and the availability of a
logger in objects) to organize application logging (if the application uses not only servlets, but also
plain old java class ) … use a context or create an object every time?
Servlets are created by the container (web server) only once, so the widespread practice of keeping a logger instance in a static variable inside a class won't hurt anything here, probably. You can take advantage of the logging capabilities that the servlet container already provides (the log method of the servlet).