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 Robert Pepersack <RP...@mdinsurance.state.md.us> on 2008/04/11 22:05:48 UTC

Same Configuration File, Different Hierarchies, and Different Log Files

I have a RepositorySelector that manages several logging hierarchies and I want to send the output of each Hierarchy to its own log file.  I would like to use the same configuration file for all of the Hierarchies, but have a different log file for each Hierarchy.  I'm using PropertyConfigurator and FileAppender.  Here are the contents of my log4j.properties file:


# Set root logger to DEBUG and add an appender named A1
log4j.rootLogger=DEBUG, A1

# Set appender A1 to be FileAppender
log4j.appender.A1=org.apache.log4j.FileAppender
log4j.appender.A1.File=C:\\JavaJobScheduler\\logs\\job_scheduler.log 
log4j.appender.A1.Append=false

# Set appender A1 to use PatternLayout
log4j.appender.A1.layout=org.apache.log4j.PatternLayout
log4j.appender.A1.layout.ConversionPattern=%d %r [%t] %-5p %c.%M(): %m%n


Can this be done through configuration, or do I have to do it programmatically?  Is there an example?

Thanks,

Bob


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


Re: Same Configuration File, Different Hierarchies, and Different Log Files

Posted by Jacob Kjome <ho...@visi.com>.
Well, you're going to want to do this programmatically, probably in the 
selector.getLoggerRepository() method (or in a static initializer() if you 
pre-configure everything) to be able to get a handle to the proper logger 
repository to run configuration upon.

In any case, you can still use the same properties file.  Simply define the 
path to the log file as a property to be resolved when the 
PropertyConfigurator configures things...

log4j.appender.A1.File=${log.path}/${log.name}.log


Now, normally you'd need to set system properties to get these resolved.  But 
that leaves you with a single value to use.  Instead, what you can do is load 
up the property file as a Properties object.  Then, prior to each call to 
configure(), add the "log.path" and "log.name" properties manually.  Then pass 
the properties object along with the repository to doConfigure(props, 
repository).  Change the values for said properties each time before you run 
configure on the other repositories and you are golden.


Jake


On Fri, 11 Apr 2008 16:05:48 -0400
  "Robert Pepersack" <RP...@mdinsurance.state.md.us> wrote:
> I have a RepositorySelector that manages several logging hierarchies and I 
>want to send the output of each Hierarchy to its own log file.  I would like 
>to use the same configuration file for all of the Hierarchies, but have a 
>different log file for each Hierarchy.  I'm using PropertyConfigurator and 
>FileAppender.  Here are the contents of my log4j.properties file:
> 
> 
> # Set root logger to DEBUG and add an appender named A1
> log4j.rootLogger=DEBUG, A1
> 
> # Set appender A1 to be FileAppender
> log4j.appender.A1=org.apache.log4j.FileAppender
> log4j.appender.A1.File=C:\\JavaJobScheduler\\logs\\job_scheduler.log 
> log4j.appender.A1.Append=false
> 
> # Set appender A1 to use PatternLayout
> log4j.appender.A1.layout=org.apache.log4j.PatternLayout
> log4j.appender.A1.layout.ConversionPattern=%d %r [%t] %-5p %c.%M(): %m%n
> 
> 
> Can this be done through configuration, or do I have to do it 
>programmatically?  Is there an example?
> 
> Thanks,
> 
> Bob
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
>For additional commands, e-mail: log4j-user-help@logging.apache.org
> 
> 


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