I'm in the process of migrating the logging of a middle-sized application from a custom solution to something more standard. I've decided on using Logback and SLF4J, and I have successfully migrated most of the Java code. However, I have quite a bit of JSPs that simply use System.out for logging. I've never worked much with JSPs, and started to wonder: how am I supposed to use proper logging in a JSP?
<%@page import="org.slf4j.Logger"%>
<%@page import="org.slf4j.LoggerFactory"%>
<%
Logger log = LoggerFactory.getLogger(getClass());
%>
<!-- ... -->
<%
log.info("Hello Logging!");
%>
This is what came to mind first, but it seems wrong on several points:
- way too verbose, and needs a lot of work to convert the existing JSPs
- a call is made to LoggerFactory.getLogger() every time the page is rendered (as opposed to a static
logger
field in a standard Java class) - I think the name of the logger is also going to be something not really straightforward this way
Is there some kind of standard, or a best practice, or anything for logging in JSPs?
Also, IIRC, there was some kind of taglib for Log4J. Is there something similar for SLF4J (or maybe Logback)?