This week's book giveaway is in the General Computing forum.
We're giving away four copies of Emmy in the Key of Code and have Aimee Lucido on-line!
See this thread for details.
Win a copy of Emmy in the Key of Code this week in the General Computing 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
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Paweł Baczyński
  • Piet Souris
  • Vijitha Kumara

ejb and web app. logging with log4j

 
Ranch Hand
Posts: 137
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Since EJB standards discourage using file i/o, how do people use log4j in EJBs to log to text files? I would like to use text file logging because alternatives such as logging to JMS or DB might be too expensive for loggin. For instance, how to load log4j.properties, where is the logging file physically located, how would that affect my EJBs?

What about J2EE Web app, why the same restriction on EJB does not apply on web app.? Again, if I use log4j in servlet, how do I load log4j.properties, and where is the logging file physically located?

Thanks.
Yan
 
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You should read Log4J tutorial.
A few beginning of answers:
- EJBs cannot directly access the file system because of their distributed nature.
- You do not need to explicitly load the log4j properties file. The log4j component does it for you. In this file you can configure appenders. Obviously you only need a FileAppender (i.e. an ordinary log file).

In case you use JBoss I have a small document showing a basic log4j config for JBoss on my website.
 
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
As EJB's cannot directly acess the file system:
one solution for logging to text file from EJB is write some Helper(Java) class.
First put the log4j.properties file in one location like C://log4j/log4j.properties.
In log4j.properties you have to mention where the log file has to be created.
In helper class:
Logger logger=Logger.getLogger("some string val");
PropertyConfigurator.configure("/log4j/log4j.properties");--this will read the log4j.properties file.
write a method which creats Logger object and return the logger to calling method.
In your EJB call this method and get the logger.
From this logger you can write debug or error or warn statements.
You can use the same class from servlet also.

Let me know if u have any Questions.

Praveena.
[ December 08, 2004: Message edited by: Praveena Venigalla ]
 
Ranch Hand
Posts: 244
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Praveena,

PropertyConfigurator.configure("/log4j/log4j.properties");--this will read the log4j.properties file.

Where is the log4j.properties file expected to be placed?

We did keep this file in the classes folder of Weblogic 8.1 Server but we get a message that the Resource file not found. The classpath in Environment variables setting has the name of the folder "classes".

Rgds,

Seetesh
 
Whose rules are you playing by? This tiny ad doesn't respect those rules:
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!