dcsimg
Appender file being created even when logger isn't being used.
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Mark_Gargan
Posted On:   Wednesday, May 4, 2005 12:16 PM

Hey folks, I'm configuring log4j from the log4j.properties file. My problem is that I want to use one logger to log to the console and another logger to log to a file. There are two appenders. One to the console and one to a file. The root logger uses both. I've created two loggers ConsoleLogger and FileLogger and set both of their additivity attributes to false so that they shouldn't inherit from the root?? Is this correct? I instantiate the logger in my code as follows. private static Logger log =Logger.getLogger("ConsoleLogger"); While the output isn't forwarded to the file the logfile.log associated with the FileLogger   More>>

Hey folks,

I'm configuring log4j from the log4j.properties file.
My problem is that I want to use one logger to log to the console and another logger to log to a file.

There are two appenders. One to the console and one to a file.
The root logger uses both.

I've created two loggers ConsoleLogger and FileLogger
and set both of their additivity attributes to false so that
they shouldn't inherit from the root?? Is this correct?

I instantiate the logger in my code as follows.

			
private static Logger log =Logger.getLogger("ConsoleLogger");


While the output isn't forwarded to the file the logfile.log
associated with the FileLogger is still created. Why is this? Is there anyway around the creation of the file if
the FileLogger isn't actually being used in the program?

Here's my log4j.properties file.
			
# Log4j configuration file.

log4j.rootCategory=DEBUG, A1, A2

# Available levels are DEBUG, INFO, WARN, ERROR, FATAL

#

#####################################
# ConsoleLogger
#####################################

log4j.logger.ConsoleLogger=DEBUG, A1
log4j.additivity.ConsoleLogger=false

# A1 is a ConsoleAppender


log4j.appender.A1=org.apache.log4j.ConsoleAppender

log4j.appender.A1.layout=org.apache.log4j.PatternLayout

log4j.appender.A1.layout.ConversionPattern=%-5p [%t] - %m%n

#####################################
# FileLogger
#####################################

log4j.logger.Filelogger=DEBUG,A2
log4j.additivity.Filelogger=false

# A2 is a DailyRollingFileAppender

log4j.appender.A2=org.apache.log4j.DailyRollingFileAppender

log4j.appender.A2.file=logs/logfile.log

log4j.appender.A2.datePattern='.'yyyy-MM-dd

log4j.appender.A2.append=true

log4j.appender.A2.layout=org.apache.log4j.PatternLayout

log4j.appender.A2.layout.ConversionPattern=%m%n


If anyone can spot what's going on I'd really appreciate any help.



Thanks,
Mark.

   <<Less
About | Sitemap | Contact