You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by "Pingili, Madhupal" <MP...@BBandT.com> on 2003/06/23 22:46:19 UTC

Can I use 2 loggers (e.g. to write to 2 files) in one Action?

Hi All,
Can I use two loggers in one Action?
I have set the Commons logging to use log4j.
I need to log error messages in one file and all other messages in another
file.
In log4j.properties, I have following lines:
# log4j properties file
log4j.rootLogger=DEBUG, stdout, rolling
log4j.logger.pilotErrors=WARN, A2

# Configure the rolling and A2 appenders to be FileAppender
log4j.appender.rolling=org.apache.log4j.FileAppender
log4j.appender.A2=org.apache.log4j.FileAppender
.......................................

In my Action,
 // The Log instance for application's debug messages.
 Log log = LogFactory.getLog(this.getClass()); //supposed to use rootLogger
 // The Log instance for application's error messages.
 Log logError = LogFactory.getLog("pilotErrors");  //supposed to use
pilotErrors logger
 log.debug("User[" + userName + "]: " + "User has " +
           "invoked initialization action in session " + session.getId() );
 logError.error("User['" + userName + "']: " + "User has " +
                "invoked initialization action in session " +
session.getId() ); 

Both debug and error messages are written in file specified with rolling
FileAppender. Why?

What am I missing??????

Thanks for any ideas,

Reddy



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


Re: Can I use 2 loggers (e.g. to write to 2 files) in one Action?

Posted by FrenzyGNX <xu...@yahoo.com.sg>.
Log4J (and most other logging packages) will log a
message if its level >= the defined level. So

log4j.rootLogger=DEBUG, stdout, rolling

will log FATAL, ERROR, INFO, DEBUG into rolling.

 --- "Pingili, Madhupal" <MP...@BBandT.com> wrote:
> Hi All,
> Can I use two loggers in one Action?
> I have set the Commons logging to use log4j.
> I need to log error messages in one file and all
> other messages in another
> file.
> In log4j.properties, I have following lines:
> # log4j properties file
> log4j.rootLogger=DEBUG, stdout, rolling
> log4j.logger.pilotErrors=WARN, A2
> 
> # Configure the rolling and A2 appenders to be
> FileAppender
> log4j.appender.rolling=org.apache.log4j.FileAppender
> log4j.appender.A2=org.apache.log4j.FileAppender
> .......................................
> 
> In my Action,
>  // The Log instance for application's debug
> messages.
>  Log log = LogFactory.getLog(this.getClass());
> //supposed to use rootLogger
>  // The Log instance for application's error
> messages.
>  Log logError = LogFactory.getLog("pilotErrors"); 
> //supposed to use
> pilotErrors logger
>  log.debug("User[" + userName + "]: " + "User has "
> +
>            "invoked initialization action in session
> " + session.getId() );
>  logError.error("User['" + userName + "']: " + "User
> has " +
>                 "invoked initialization action in
> session " +
> session.getId() ); 
> 
> Both debug and error messages are written in file
> specified with rolling
> FileAppender. Why?
> 
> What am I missing??????
> 
> Thanks for any ideas,
> 
> Reddy
> 
> 
> 
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
> struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail:
> struts-user-help@jakarta.apache.org
>  

__________________________________________________
Do You Yahoo!?
Send free SMS from your PC!
http://sg.sms.yahoo.com

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