[slf4j-user] log to multiple log files
Ceki Gülcü
ceki at qos.ch
Mon Sep 13 22:24:10 CEST 2010
Hi Luke,
SiftingAppender [1] is your friend. As its name intimates, a
SiftingAppender can be used to separate (or sift) logging according to a
given runtime attribute. For example, SiftingAppender can separate
logging events according to user sessions, so that the logs generated by
each user go into distinct log files, one log file per user.
BTW, you can't do what you are asking with JUL, at least not without
writing tons of new code.
[1] http://logback.qos.ch/manual/appenders.html#SiftingAppender
On 12/09/2010 8:07 AM, Luke Vanderfluit wrote:
> 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