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 Matthew Hixson <hi...@poindextrose.org> on 2002/04/19 08:27:26 UTC

logging different things to different files

Hi,
  I am working on a web app that needs to log different, mostly unrelated,
messages to two completely different files.  I have spent the last hour
trying to find any and all mention of logging to two different files
within one web app and can't even find a single example.  I fully
understand log4j's concept of hierarchical loggers and appenders.  What
I'd like to know is how to setup one file for logging business events and
another file for logging system events so that within a class I can do
this: 

  static Logger businessLogger = Logger.getLogger("business");
  static Logger systemLogger = Logger.getLogger("system");

and then inside a method do:

   businessLogger.info(user + "has logged in");
   ...
   systemLogger.info("database is unreachable");

Anyone know how to configure a single log4j.properties file that lets me
do that?
  Again, I do _not_ want the same messages logged to both files.  I want
to be able to log to only one file at a time.  All of my attempts so far
have either not worked at all or they dump all messages to both files.
  Thanks for any help,
   -M@


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: logging different things to different files

Posted by Matthew Hixson <hi...@poindextrose.org>.
Have I read what? 
 -M@


On Fri, 19 Apr 2002, Scott Farquhar wrote:

> Have you read this?
> 
> 
> Matthew Hixson wrote:
> > Hi,
> >   I am working on a web app that needs to log different, mostly unrelated,
> > messages to two completely different files.  I have spent the last hour
> > trying to find any and all mention of logging to two different files
> > within one web app and can't even find a single example.  I fully
> > understand log4j's concept of hierarchical loggers and appenders.  What
> > I'd like to know is how to setup one file for logging business events and
> > another file for logging system events so that within a class I can do
> > this: 
> > 
> >   static Logger businessLogger = Logger.getLogger("business");
> >   static Logger systemLogger = Logger.getLogger("system");
> > 
> > and then inside a method do:
> > 
> >    businessLogger.info(user + "has logged in");
> >    ...
> >    systemLogger.info("database is unreachable");
> > 
> > Anyone know how to configure a single log4j.properties file that lets me
> > do that?
> >   Again, I do _not_ want the same messages logged to both files.  I want
> > to be able to log to only one file at a time.  All of my attempts so far
> > have either not worked at all or they dump all messages to both files.
> >   Thanks for any help,
> >    -M@
> > 
> > 
> > --
> > To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> > For additional commands, e-mail: <ma...@jakarta.apache.org>
> > 
> > 
> 
> 
> -- 
> Scott Farquhar :: scott@atlassian.com
> 
> Atlassian :: http://www.atlassian.com
>       Supporting YOUR J2EE World
> 
> 
> --
> To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>
> 


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: logging different things to different files

Posted by Scott Farquhar <sc...@atlassian.com>.
Have you read this?


Matthew Hixson wrote:
> Hi,
>   I am working on a web app that needs to log different, mostly unrelated,
> messages to two completely different files.  I have spent the last hour
> trying to find any and all mention of logging to two different files
> within one web app and can't even find a single example.  I fully
> understand log4j's concept of hierarchical loggers and appenders.  What
> I'd like to know is how to setup one file for logging business events and
> another file for logging system events so that within a class I can do
> this: 
> 
>   static Logger businessLogger = Logger.getLogger("business");
>   static Logger systemLogger = Logger.getLogger("system");
> 
> and then inside a method do:
> 
>    businessLogger.info(user + "has logged in");
>    ...
>    systemLogger.info("database is unreachable");
> 
> Anyone know how to configure a single log4j.properties file that lets me
> do that?
>   Again, I do _not_ want the same messages logged to both files.  I want
> to be able to log to only one file at a time.  All of my attempts so far
> have either not worked at all or they dump all messages to both files.
>   Thanks for any help,
>    -M@
> 
> 
> --
> To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>
> 
> 


-- 
Scott Farquhar :: scott@atlassian.com

Atlassian :: http://www.atlassian.com
      Supporting YOUR J2EE World


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: logging different things to different files

Posted by Matthew Hixson <hi...@poindextrose.org>.
Thanks for the help, Scott.  I've gotten it working now.  Below is the
file I'm using.
  I noticed in your example you have:

log4j.appender.business.Threshold=DEBUG

If I raise that to WARN does that mean that any
businessLogger.debug("msg") statements won't get logged since WARN is
higher than DEBUG?
  Thanks again for the help. 
   -M@


log4j.rootLogger=DEBUG, console
log4j.rootCategory=DEBUG, console

log4j.category.business = DEBUG, business
log4j.additivity.business = false

log4j.category.system = DEBUG, system
log4j.additivity.system = false

## business.log - business relevant events get logged here

log4j.appender.business=org.apache.log4j.RollingFileAppender
log4j.appender.business.File=business.log

log4j.appender.business.MaxFileSize=100KB
# Keep one backup file
log4j.appender.business.MaxBackupIndex=1

log4j.appender.business.layout=org.apache.log4j.PatternLayout
log4j.appender.business.layout.ConversionPattern=%d{dd MMM yyyy HH:mm:ss}
%5p (%F:%L) - [%m]%n

## system.log - system level events get logged here

log4j.appender.system=org.apache.log4j.RollingFileAppender
log4j.appender.system.File=system.log

log4j.appender.system.MaxFileSize=100KB
# Keep one backup file
log4j.appender.system.MaxBackupIndex=1

log4j.appender.system.layout=org.apache.log4j.PatternLayout
log4j.appender.system.layout.ConversionPattern=%d{dd MMM yyyy HH:mm:ss}
%5p (%F:%L) - [%m]%n

# only messages set to this and higher will be logged
log4j.logger.com.versaly=DEBUG


On Fri, 19 Apr 2002, Scott Farquhar wrote:

> Have you read this?
> 
> http://jakarta.apache.org/log4j/docs/manual.html
> 
> Here is the sample file:
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> # A log4j properties file
> 
> # Set root logger level to DEBUG and its only appender to console.
> log4j.rootLogger=DEBUG, console
> log4j.rootCategory=DEBUG, console
> 
> log4j.category.business = DEBUG, business
> log4j.additivity.business = false
> 
> log4j.category.system = DEBUG, system
> log4j.additivity.system = false
> 
> log4j.appender.console=org.apache.log4j.ConsoleAppender
> log4j.appender.console.Threshold=DEBUG
> log4j.appender.console.layout=org.apache.log4j.PatternLayout
> log4j.appender.console.layout.ConversionPattern= console-appender %p 
> [(%c{4})] %m%n
> 
> log4j.appender.business=org.apache.log4j.FileAppender
> log4j.appender.business.File=business.log
> log4j.appender.business.Threshold=DEBUG
> log4j.appender.business.layout=org.apache.log4j.PatternLayout
> log4j.appender.business.layout.ConversionPattern= business-appender %p 
> [(%c{4})] %m%n
> 
> log4j.appender.system=org.apache.log4j.FileAppender
> log4j.appender.system.File=business.log
> log4j.appender.system.Threshold=DEBUG
> log4j.appender.system.layout=org.apache.log4j.PatternLayout
> log4j.appender.system.layout.ConversionPattern= system-appender %p 
> [(%c{4})] %m%n
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> 
> Matthew Hixson wrote:
> > Hi,
> >   I am working on a web app that needs to log different, mostly unrelated,
> > messages to two completely different files.  I have spent the last hour
> > trying to find any and all mention of logging to two different files
> > within one web app and can't even find a single example.  I fully
> > understand log4j's concept of hierarchical loggers and appenders.  What
> > I'd like to know is how to setup one file for logging business events and
> > another file for logging system events so that within a class I can do
> > this: 
> > 
> >   static Logger businessLogger = Logger.getLogger("business");
> >   static Logger systemLogger = Logger.getLogger("system");
> > 
> > and then inside a method do:
> > 
> >    businessLogger.info(user + "has logged in");
> >    ...
> >    systemLogger.info("database is unreachable");
> > 
> > Anyone know how to configure a single log4j.properties file that lets me
> > do that?
> >   Again, I do _not_ want the same messages logged to both files.  I want
> > to be able to log to only one file at a time.  All of my attempts so far
> > have either not worked at all or they dump all messages to both files.
> >   Thanks for any help,
> >    -M@
> > 
> > 
> > --
> > To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> > For additional commands, e-mail: <ma...@jakarta.apache.org>
> > 
> > 
> 
> 
> -- 
> Scott Farquhar :: scott@atlassian.com
> 
> Atlassian :: http://www.atlassian.com
>       Supporting YOUR J2EE World
> 
> 
> --
> To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>
> 


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: logging different things to different files

Posted by Matthew Hixson <hi...@poindextrose.org>.
Oh, thanks.  I'll give that a try.  Yes, I did read that entire page, but
it was still not clear to me how to create a new logger.
  Thanks,
   -M@


On Fri, 19 Apr 2002, Scott Farquhar wrote:

> Have you read this?
> 
> http://jakarta.apache.org/log4j/docs/manual.html
> 
> Here is the sample file:
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> # A log4j properties file
> 
> # Set root logger level to DEBUG and its only appender to console.
> log4j.rootLogger=DEBUG, console
> log4j.rootCategory=DEBUG, console
> 
> log4j.category.business = DEBUG, business
> log4j.additivity.business = false
> 
> log4j.category.system = DEBUG, system
> log4j.additivity.system = false
> 
> log4j.appender.console=org.apache.log4j.ConsoleAppender
> log4j.appender.console.Threshold=DEBUG
> log4j.appender.console.layout=org.apache.log4j.PatternLayout
> log4j.appender.console.layout.ConversionPattern= console-appender %p 
> [(%c{4})] %m%n
> 
> log4j.appender.business=org.apache.log4j.FileAppender
> log4j.appender.business.File=business.log
> log4j.appender.business.Threshold=DEBUG
> log4j.appender.business.layout=org.apache.log4j.PatternLayout
> log4j.appender.business.layout.ConversionPattern= business-appender %p 
> [(%c{4})] %m%n
> 
> log4j.appender.system=org.apache.log4j.FileAppender
> log4j.appender.system.File=business.log
> log4j.appender.system.Threshold=DEBUG
> log4j.appender.system.layout=org.apache.log4j.PatternLayout
> log4j.appender.system.layout.ConversionPattern= system-appender %p 
> [(%c{4})] %m%n
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> 
> Matthew Hixson wrote:
> > Hi,
> >   I am working on a web app that needs to log different, mostly unrelated,
> > messages to two completely different files.  I have spent the last hour
> > trying to find any and all mention of logging to two different files
> > within one web app and can't even find a single example.  I fully
> > understand log4j's concept of hierarchical loggers and appenders.  What
> > I'd like to know is how to setup one file for logging business events and
> > another file for logging system events so that within a class I can do
> > this: 
> > 
> >   static Logger businessLogger = Logger.getLogger("business");
> >   static Logger systemLogger = Logger.getLogger("system");
> > 
> > and then inside a method do:
> > 
> >    businessLogger.info(user + "has logged in");
> >    ...
> >    systemLogger.info("database is unreachable");
> > 
> > Anyone know how to configure a single log4j.properties file that lets me
> > do that?
> >   Again, I do _not_ want the same messages logged to both files.  I want
> > to be able to log to only one file at a time.  All of my attempts so far
> > have either not worked at all or they dump all messages to both files.
> >   Thanks for any help,
> >    -M@
> > 
> > 
> > --
> > To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> > For additional commands, e-mail: <ma...@jakarta.apache.org>
> > 
> > 
> 
> 
> -- 
> Scott Farquhar :: scott@atlassian.com
> 
> Atlassian :: http://www.atlassian.com
>       Supporting YOUR J2EE World
> 
> 
> --
> To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>
> 


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: logging different things to different files

Posted by Scott Farquhar <sc...@atlassian.com>.
Have you read this?

http://jakarta.apache.org/log4j/docs/manual.html

Here is the sample file:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# A log4j properties file

# Set root logger level to DEBUG and its only appender to console.
log4j.rootLogger=DEBUG, console
log4j.rootCategory=DEBUG, console

log4j.category.business = DEBUG, business
log4j.additivity.business = false

log4j.category.system = DEBUG, system
log4j.additivity.system = false

log4j.appender.console=org.apache.log4j.ConsoleAppender
log4j.appender.console.Threshold=DEBUG
log4j.appender.console.layout=org.apache.log4j.PatternLayout
log4j.appender.console.layout.ConversionPattern= console-appender %p 
[(%c{4})] %m%n

log4j.appender.business=org.apache.log4j.FileAppender
log4j.appender.business.File=business.log
log4j.appender.business.Threshold=DEBUG
log4j.appender.business.layout=org.apache.log4j.PatternLayout
log4j.appender.business.layout.ConversionPattern= business-appender %p 
[(%c{4})] %m%n

log4j.appender.system=org.apache.log4j.FileAppender
log4j.appender.system.File=business.log
log4j.appender.system.Threshold=DEBUG
log4j.appender.system.layout=org.apache.log4j.PatternLayout
log4j.appender.system.layout.ConversionPattern= system-appender %p 
[(%c{4})] %m%n
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Matthew Hixson wrote:
> Hi,
>   I am working on a web app that needs to log different, mostly unrelated,
> messages to two completely different files.  I have spent the last hour
> trying to find any and all mention of logging to two different files
> within one web app and can't even find a single example.  I fully
> understand log4j's concept of hierarchical loggers and appenders.  What
> I'd like to know is how to setup one file for logging business events and
> another file for logging system events so that within a class I can do
> this: 
> 
>   static Logger businessLogger = Logger.getLogger("business");
>   static Logger systemLogger = Logger.getLogger("system");
> 
> and then inside a method do:
> 
>    businessLogger.info(user + "has logged in");
>    ...
>    systemLogger.info("database is unreachable");
> 
> Anyone know how to configure a single log4j.properties file that lets me
> do that?
>   Again, I do _not_ want the same messages logged to both files.  I want
> to be able to log to only one file at a time.  All of my attempts so far
> have either not worked at all or they dump all messages to both files.
>   Thanks for any help,
>    -M@
> 
> 
> --
> To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>
> 
> 


-- 
Scott Farquhar :: scott@atlassian.com

Atlassian :: http://www.atlassian.com
      Supporting YOUR J2EE World


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>