This week's book giveaway is in the Reactive Progamming forum.
We're giving away four copies of Reactive Streams in Java: Concurrency with RxJava, Reactor, and Akka Streams and have Adam Davis on-line!
See this thread for details.
Win a copy of Reactive Streams in Java: Concurrency with RxJava, Reactor, and Akka Streams this week in the Reactive Progamming forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Ganesh Patekar

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

 
Ranch Hand
Posts: 250
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 250
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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();??
 
drifter
Posts: 1364
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 250
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 1364
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 250
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 1364
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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)?
 
this is supposed to be a surprise, but it smells like a tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!