• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

EJB Logging

 
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
sharp shooter, and author
Posts: 1913
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Simon! I really wish something concrete is provided by the specs!
 
Saloon Keeper
Posts: 27763
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Acetylsalicylic acid is aspirin. This could be handy too:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic