aspose file tools*
The moose likes Other Open Source Projects and the fly likes can BasicConfigurator.configure() read log4j.properties and log output to fileAppender? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Other Open Source Projects
Bookmark "can BasicConfigurator.configure() read log4j.properties and log output to fileAppender?" Watch "can BasicConfigurator.configure() read log4j.properties and log output to fileAppender?" New topic
Author

can BasicConfigurator.configure() read log4j.properties and log output to fileAppender?

peter tong
Ranch Hand

Joined: Mar 15, 2008
Posts: 240
as captioned, I always see article said BasicConfigurator can only log message to console output,
so can BasicConfigurator.configure() read log4j.properties and log message to fileAppender, assume
fileAppender is defined in log4j.properties?
peter tong
Ranch Hand

Joined: Mar 15, 2008
Posts: 240
peter tong wrote:as captioned, I always see article said BasicConfigurator can only log message to console output,
so can BasicConfigurator.configure() read log4j.properties and log message to fileAppender, assume
fileAppender is defined in log4j.properties?


Oh, I found that even I comment out the BasicConfigurator.configure();
the web application can still read log4j.properties and add log to fileAppender.
is this true?
if so, then what is the need of the statement BasicConfigurator.configure();??
Carol Enderlin
drifter
Ranch Hand

Joined: Oct 10, 2000
Posts: 1364
There are many ways to configure log4j. BasicConfigurator.configure() does not require the use of a log4j.properties file. If you are using a log4j.properties or log4j.xml file no other configuration is required.
peter tong
Ranch Hand

Joined: Mar 15, 2008
Posts: 240
Carol Enderlin wrote:There are many ways to configure log4j. BasicConfigurator.configure() does not require the use of a log4j.properties file. If you are using a log4j.properties or log4j.xml file no other configuration is required.


"If you are using a log4j.properties or log4j.xml file no other configuration is required"
ok, let me clarify this statement, is this mean that if I place log4j.properties in WEB-INF/class folder and log4j.jar in WEB-INF/lib folder, then no need to use BasicConfigurator.configure() or PropertyConfigurator.configure(...) in my source code, the log4j.properties will "automatically" read by the source?

Thanks
Carol Enderlin
drifter
Ranch Hand

Joined: Oct 10, 2000
Posts: 1364
Yes, log4j.properties or log4j.xml on classpath (example is in WEB-INF/classes) results in configuration without calling one of the configure methods. Placement of jar file can depend on your environment.

Not sure what you are asking because I thought that was what you experienced.
peter tong
Ranch Hand

Joined: Mar 15, 2008
Posts: 240
Carol Enderlin wrote:Yes, log4j.properties or log4j.xml on classpath (example is in WEB-INF/classes) results in configuration without calling one of the configure methods. Placement of jar file can depend on your environment.

Not sure what you are asking because I thought that was what you experienced.


ok, thanks.
I have two more question.

1) under what condition do we need to use BasicConfigurator.configure() or PropertyConfigurator.configure(...)?

2) with the following log4j.properties



I found that I need to comment the statement
#log4j.appender.TomcatLogger.File=${catalina.home}/logs/tomcat.log
for the smart.log to seen in ${catalina.home}/logs/
if I uncomment that statement, the smart.log cannot be found, what is the reason?

I am using tomcat 5.5. log4j.1.2.8
Carol Enderlin
drifter
Ranch Hand

Joined: Oct 10, 2000
Posts: 1364
Not using tomcat, I tried your properties file.

With that line commented (#log4j.appender.TomcatLogger.File=${catalina.home}/logs/tomcat.log) I get warnings and error

log4j:WARN File option not set for appender [TomcatLogger].
log4j:WARN Are you using FileAppender instead of ConsoleAppender?
log4j:ERROR Either File or DatePattern options are not set for appender [TomcatLogger].


With that line uncommented I get no warnings or errors and it creates both log files.

Are you getting errors (wherever your tomcat puts that)?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: can BasicConfigurator.configure() read log4j.properties and log output to fileAppender?