• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Log4J configuration problem

 
Kjeld Sigtermans
Ranch Hand
Posts: 127
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I am trying to use Log4J logging in a web application, deployed on BEA.
I am writing this down from memory since I can not access my code right now. My apologies.

First, in a Java class (e.g. mypackage.MyClass), I put code like:

Second, I have created a log4j.properties file and I have put it in the web project's WEB-INF/classes folder (later on, I tried putting it in other classpath locations as well).
The properties file basically just defines the root logger, and configures it to a console output appender, at INFO level. I copied the property file content directly from an example, so I assume nothing is wrong with it (later on I tried to create a specific logger for "mypackage" as well).

When starting up the server and application, and passing through the code of MyClass, the following appears in the console output:

log4j:WARN No appenders could be found for logger (mypackage.MyClass)
log4j:WARN Please initialize the log4j system properly.

What do I need to do to get it working? It is a web application, so I assume I do not need to call some initialization method in advance, like I noticed in stand-alone Java application examples.

Thanks!
Kjeld
 
Paul Clapham
Sheriff
Pie
Posts: 20729
30
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And does this logging configuration work (i.e. produce log output) when you use it in a simpler environment? E.g. not in a Java EE container, but in a plain old Java application?
 
Kjeld Sigtermans
Ranch Hand
Posts: 127
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have not tried that, thanks. I will in the morning and post the result here.
 
Kjeld Sigtermans
Ranch Hand
Posts: 127
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well the log4j.properties file works fine in a standalone Java application.
This is the file:
Note that my standalone Java app is in a package called log4jtest.

I put the log4j.properties file in the classpath and before doing any logging I initialize log4j using:

I understand that PropertyConfigurator.configure(...) does the trick, but I doubt this is the way to initialize Log4J in a web application?
 
Sean Clark
Rancher
Posts: 377
Android Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey,
I think the problem may be that the web application does not have a console as such.
Have you tried using the file appender in the web application?

Sean
 
Kjeld Sigtermans
Ranch Hand
Posts: 127
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried, but nog log file.
Right now I am creating a SetupServlet , loaded on startup, containing the initialization code.
Can't image this is the way to go, though.

Thanks!
 
Tanzy Akhtar
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Kjeld, i am curious whether have you resolved this problem.
Please share with us if you find the solution so that it ll be helpful to others.


Thanks,
Tanzy.
 
Kjeld Sigtermans
Ranch Hand
Posts: 127
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Tanzy,

No change since my last post. The development team agreed in creating a Servlet called InitServlet that is loaded on startup, initializing the code in its 'init(ServletConfig)' method. Here's the method:



And the web.xml snipplet:



Grtz,
Kjeld
 
Tanzy Akhtar
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Kjeld for sharing the solution.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic