You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-user@logging.apache.org by Ian Huynh <ia...@hubspan.com> on 2004/03/02 23:51:32 UTC

Is there a 'buffered' logging concept? buffer message prior to knowing the Category of a logger

In normal usage of Log4J, this is a standard practice

  Logger logger = Logger.getLogger("com.acme.someclass");

  if (logger.isDebugEnabled()) 
  {
     logger.debug("This is my debug message" );
  }


What if the Category (ie  'com.acme.someclass') isn't a static value but some
dynamic value ? One typical example would be an application that needs to parse some request and
within the request, there are some contextual information that defines the Category name ?

So prior to knowing whether the Category of a logger is debug or infor etc.., we still like to
buffer some messages and then once the Category can be defined, the debug messages can be flushed out
or throw away.

eg. 

   Get a 'Buffer' Logger instance
   Get Request from Client
   logDebug("Got request from Client. about to parse")
   
   parsedRequest = ParseRequest()

   logDebug("Request Parsed")

   String contextInfo = Get from parsedRequest 

   Re-get the Log4j logger using contextInfo as category (ie   newLogger= Logger.getLogger( contextInfo ) )

   if ( newLogger is debug enabled)
      flush all the previous messages to the appender

I am curious if anyone has similar requirements or have implememented something similar.  I've thought
about writing a custom BufferLogger but would rather see what else is out there.

Thanks in advance.

   






---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org