• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

EJB Logging

 
Velmurugan Periasamy
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Simon Brown
sharp shooter, and author
Ranch Hand
Posts: 1913
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 95
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Simon! I really wish something concrete is provided by the specs!
 
Tim Holloway
Saloon Keeper
Pie
Posts: 18277
56
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic