This week's giveaway is in the Spring forum.
We're giving away four copies of REST with Spring (video course) and have Eugen Paraschiv on-line!
See this thread for details.
The moose likes EJB and other Java EE Technologies and the fly likes EJB Logging Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "EJB Logging" Watch "EJB Logging" New topic

EJB Logging

Velmurugan Periasamy
Ranch Hand

Joined: Nov 09, 2000
Posts: 95
Section 24.1.2 of the EJB 2.0 spec states "An
enterprise bean must not use the package to attempt to access files and directories in the file system."
The EJB API does not provide a logging mechanism
similar to the ServletContext.log() methods.
How does one log methods in an EJB (besides
System.out and w/o violating the spec's)?

------------------------------------------------------------------------------------<BR>Velmurugan Periasamy<BR>Sun Certified Java Programmer for Java 2 Platform<BR>Sun Certified Web Component Developer for J2EE platform<BR>Sybase Certified EAServer Developer (similar to jCert level 3)<BR>------------------------------------------------------------------------------------<BR>Study notes for Sun Java Certification<BR><A HREF="" TARGET=_blank rel="nofollow"></A><BR>------------------------------------------------------------------------------------
Simon Brown
sharp shooter, and author
Ranch Hand

Joined: May 10, 2000
Posts: 1913
A good question, and one that is not easily answered. Accessing files and directories from within an EJB container is possible, although one of the reason why it isn't "allowed" is because you are using the EJB container for the infrastructure rather than the underlying operating system (if you see what I mean). For this reason, trying to access specific files and directories isn't portable.
However, most (all?) application servers don't actually restrict access to the package.
In terms of logging, you'll notice that many people use log4j, which of course under the hood uses the packages. From what I've seen, most people just use log4j (or some other framework) and ignore such restrictions.
Out of interest, has anybody actually seen an app server in which log4j doesn't work?
Velmurugan Periasamy
Ranch Hand

Joined: Nov 09, 2000
Posts: 95
Thanks Simon! I really wish something concrete is provided by the specs!
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 17257

This is definitely an area where you have to trade the "should" nots for "must have"s. Note that Sun doesn't outright ban I/O, but discourages it for reasons of bean portablity and to avoid possible conflicts with activities manmaged by the container.
In real life, I've never stinted at placing System.out.print's in an EJB for development purposes. But for a production EJB, I don't want them - you don't know where that stuff is going to end up or what else it's going to be buried in. If there's a need for production message-display, I use a logging package so that my EJB messages will go to a standard location and be properly prioritized/obscurable.
Another reason for using logging over straight I/O is that a logger has the option to set off alarms, page somebody, and/or do other exotic functions.

An IDE is no substitute for an Intelligent Developer.
I agree. Here's the link:
subject: EJB Logging
It's not a secret anymore!