Meaningless Drivel is fun!*
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 Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "EJB Logging" Watch "EJB Logging" New topic
Author

EJB Logging

Velmurugan Periasamy
Ranch Hand

Joined: Nov 09, 2000
Posts: 95
Hello,
Section 24.1.2 of the EJB 2.0 spec states "An
enterprise bean must not use the java.io 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)?
Thanks.


------------------------------------------------------------------------------------<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="http://www.geocities.com/velmurugan_p/" TARGET=_blank rel="nofollow">http://www.geocities.com/velmurugan_p/</A><BR>------------------------------------------------------------------------------------
Simon Brown
sharp shooter, and author
Ranch Hand

Joined: May 10, 2000
Posts: 1913
    
    6
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 java.io package.
In terms of logging, you'll notice that many people use log4j, which of course under the hood uses the java.io 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?
Simon
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: 15947
    
  19

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.


Customer surveys are for companies who didn't pay proper attention to begin with.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: EJB Logging
 
Similar Threads
How will i get refrence of printWriter
Threads behaving weirdly
Common-Logging and Log4j in Hibernate
About accessing EJB
where to get info about commons logging, log4j and java.util.logging....