How do I implement a logging system in my beans?
Using java.io is prohibitedUsing the java.io package from within a bean is prohibited. The EJB 1.1 Specification, section 18.1.2 (Programming Restrictions) states the following:
An enterprise bean must not use the java.io package to attempt to access files and directories in the file system.
The file system APIs are not well-suited for business components to access data. Business components should use a resource manager API, such as JDBC API, to store data.
The EJB 1.1 specification is available for download from http://java.sun.com/products/ejb/docs.html
Alternative SolutionsTo perform logging operations you must you a resource connection supported by the EJB programming model. EJB servers may support several resource connection options, which can be used to log events as shown below:
- JDBC (javax.sql.DataSource) : Write log events in to a relational database.
- URL (java.net.URL) : Write log events to a custom logging server or post them to a web server.
- JavaMail (javax.mail.Session) : E-mail log events to a special account
- JMS (javax.jms.QueueConnectionFactory | javax.jms.TopicConnectionFactory) : Send the log events as messages.