can you give me please a step by step procedure to follow, in order to make log4j work on an ejb module? the situation is this: i have my ejbmodule, which is using hibernate to perform some fetching tasks, and i want to log everything. I want to use log4j but i can not understand some steps of the others procedure described on the web like those from jboss.
Can you please tell me what i should do, step by step?
As far as i am:
I have got my configuration file (and i don't know where to put it)
I have got the log4j.jar (and i don't know where to place it)
I don't know how to initialize the log environment (i have an ejb session bean which on startup initializes hibernate, i would like one to initialize the logger)
Can anyone of you help me please?
Thanks in advance
EDIT: thanks for the fist suggestion it might help but i don't undestand how others may have META-INF in the ear. My project looks like 3 projects togheder:
- MyprojectLogic (which contains the ejbmodules)
- MyprojectLogicClient (which contains all the interfaces, it is the library to be given to the client)
- MyprojectLogicEAR (which actually contains nothing, i did not get what is its purpose)
ANSWER: see below or check here javafortheweb or blog
Jboss already comes with log4j. When developing your EJB you need to:
import org.apache.log4j.Logger;
private static Logger logger = Logger.getLogger(YourEJBClass.class);
logger.info("my log");
JBoss already comes with a configuration file under
%JBOSS_FOLDER%/standalone/configuration/standalone.xml
. By default, your logger will output to server.log and console, but you can add some appender to output your app logs to another file.Here is an example, edit that file and add the following snippets (following the definition of the file):
Restart the server and you should see the new myappfile.log in the folder. Make sure your app logs something, for example, adding logger.info("my servlet info log") in some servlet and call it from the browser. You'll also see this log in the console
If you need further customization, have a look at log4j help.