The simplest thing to do is to set aside a logger name/hierarchy for this purpose:
Ex) If your logger names correspond to your classnames (a common approach) then you are using names like com.foobar.p1.c1 Then your loggers for this hierarchy could do the normal level based filtering. When you need to log a message that is 'always' logged. You could use a different naming convention (like always.com.foobar....) This way you can set up logging for a category name of 'always' to record all log messages. The 'com' category would use level based filtering of messages. Tom. -----Original Message----- From: Sheward, Barry [mailto:[EMAIL PROTECTED] Sent: Tuesday, January 27, 2004 6:43 PM To: [EMAIL PROTECTED] Cc: Sheward, Barry Subject: methods to always log, regardless of the current priority Hi, We use Log4J extensively and find that sometimes we always want to log a message, but the message is simply for informational purposes. Using Logger/Category.fatal() would potentially frighten users, but using Logger/Category.info() may not show up if they have reconfigured logging. While it would be possible to save the priority for the category, change the priority for the category, log the message and then restore the priority for the category, this seemed very inefficient both in terms of lines of code and run-time performance. So, I developed the following four (incredibly simple) methods, which regardless of the current priority of the Logger/Category, will always log the message. The diff is from the 1.2.8 source. I hereby donate this code to the Apache Software Foundation. Please consider adding these methods to Log4J. Regards, Barry Sheward 1037a1038,1111 > > /** > Log a message object with the [EMAIL PROTECTED] Priority#INFO INFO} priority > regardless of whether <code>INFO</code> output is enabled for > this category. > > <p>This method converts the message object > (passed as parameter) to a string by invoking the appropriate > [EMAIL PROTECTED] ObjectRenderer}. It then proceeds to call all the > registered appenders in this category and also higher in the > hierarchy depending on the value of the additivity flag. > > <p><b>WARNING</b> Note that passing a [EMAIL PROTECTED] Throwable} to this > method will print the name of the <code>Throwable</code> but no > stack trace. To print a stack trace use the [EMAIL PROTECTED] #debug(Object, > Throwable)} form instead. > > @param message the message object to log. */ > public > void always(Object message) { > forcedLog(FQCN, Priority.INFO, message, null); > } > > > /** > Log a message object with the <code>INFO</code> priority including > the stack trace of the [EMAIL PROTECTED] Throwable} <code>t</code> passed as > parameter regardless of whether <code>INFO</code> priority output > is enabled for this category. > > <p>See [EMAIL PROTECTED] #always(Object)} form for more detailed information. > > @param message the message object to log. > @param t the exception to log, including its stack trace. */ > public > void always(Object message, Throwable t) { > forcedLog(FQCN, Priority.INFO, message, t); > } > > /** > Log a message object with the specified priority > regardless of whether the specified priority output is enabled for > this Category. > > <p>See [EMAIL PROTECTED] #always(Object)} form for more detailed information. > > <p><b>WARNING</b> Note that passing a [EMAIL PROTECTED] Throwable} to this > method will print the name of the <code>Throwable</code> but no > stack trace. To print a stack trace use the [EMAIL PROTECTED] #debug(Object, > Throwable)} form instead. > > @param message the message object to log. > @param priority the priority to log the message at. */ > public > void always(Object message, Priority priority) { > forcedLog(FQCN, priority, message, null); > } > > > /** > Log a message object with the specified priority including > the stack trace of the [EMAIL PROTECTED] Throwable} <code>t</code> passed as > parameter regardless of whether specified priority output > is enabled for this Category. > > <p>See [EMAIL PROTECTED] #debug(Object)} form for more detailed information. > > @param message the message object to log. > @param t the exception to log, including its stack trace. > @param priority the priority to log the message at. */ > public > void always(Object message, Throwable t, Priority priority) { > forcedLog(FQCN, priority, message, t); > } --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]