[slf4j-user] log to multiple log files

Luke Vanderfluit luke.vanderfluit at e3learning.com.au
Sun Sep 12 08:07:24 CEST 2010


Hi.
I have the following situation...
Tomcat 6 running a web application.
Currently we are using the jcl to slf4j bridge because we have some
legacy commons logging in the app and slf4j jdk14.
There are several places in the app that I want logging to take place,
and I want to log to several different log files.

We have a huge amount of JSPs in our web app and we want to be able to
log to different log files when required.
So, for example, when logging from admin jsps I want the logging to
end up in an admin log file and when logging from customer jsps I want
the log statements to end up in a customer log file. Each time
something is logged I want to be able to pass specific user-related
data to the log.

I envisage that I will have a LogUtil class that has static methods
for logging. I want to be able to pass a set of strings into the
static method (say with varargs) and then have the static method take
responsibility for writing to the correct logfile, based on the
strings it has received.

So, for example, in jsp a.jsp, I call
LogUtil.doLog("adminLogfile","message"). This method should then be
able to log to the appropriate log file ("adminLogfile") and include
the account_id of the person logged in (freely available from the
session), time and date and any other data I care to pass along...

I hope this makes sense so far.
Since we are currently using slf4j, Im hoping to be able to achieve
this with slf4j, however since we are using slf4j with JUL, Im not
sure how to do it. It seems that log4j and logback have better means
at their disposal for doing stuff like this. Im thinking of MDC and
other log4j mechanisms which allow for finer grained log
discernment...

Since Im in the process of learning how java logging works, and it
seems Im not the only one judging by the number of tutorials that just
repeat the same thing over and over but dont go into the details of
how to do stuff, Im looking for some help here to achieve my goal...

Any help appreciated.
TIA.

Luke Vanderfluit


More information about the slf4j-user mailing list