Logger
Hi,
I have a Spring MVC webapps that needs some server side logging so I configured Log4J in my Spring MVC
<listener>
<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
</listener>
In my controller, I logged all user transaction.
@Controller
public class MyController {
protected final Log logger = LogFactory.getLog(getClass());
public String setup(){
MyObject object = new MyObject();
logger.info("User check in data...." + object.data);
}
}
I have some questions though:
- Are Logging in a Spring MVC Webapps considered a costly transaction? I mean will this slowdown my app?
- In a production enviroment, will it be OK if I leave out this logger.info? I need to add this for traceability of each transaction and is a requirement
but I am worried about the impact of these.
Thanks
Log4j has almost no overhead itself. It is designed to be compiled into your code and enabled or disabled by configuration.
When it is disabled, it is very fast. The only problem you may have is in preparing the log message, which will then not be used. You can avoid this with a guard:
When it is enabled, it obviously takes some time to write the message to the log file/daemon/database. However, since you have enabled it, you need that log message (you say you have a traceability requirement), so the fair comparison would be to creating the log message in another way. And here, the log4j overhead (versus calling the logging backend directly) is minimal.
The full cost of logging the message will thus be determined by what kind of backend you are using (and not by log4j itself).