I'm new to struts and tried to add Log4j the same way I do it for my desktop applications:
I create a Log4jConfigFile.xml with my parameters. In my classes I use
DOMConfigurator.configure(Log4jConfigFile.xml) to start the logging.
In Struts (I'm running it in Websphere 5.1.1) I always get a FileNotFoundException on the xml-file.
I have now placed the xml-file in every directory I could find in my application, but the result stays the same (filenotfoundexception).
Can anybody help me please because logging is rather important in my application.
Thx
-
struts log4j (5 messages)
- Posted by: jan vos
- Posted on: August 04 2005 06:29 EDT
Threaded Messages (5)
- struts log4j by Lars Vonk on August 04 2005 10:13 EDT
- struts log4j by jan vos on August 05 2005 02:58 EDT
-
struts log4j by Lars Vonk on August 05 2005 04:02 EDT
-
struts log4j by jan vos on August 05 2005 04:14 EDT
- struts log4j by Lars Vonk on August 05 2005 05:21 EDT
-
struts log4j by jan vos on August 05 2005 04:14 EDT
-
struts log4j by Lars Vonk on August 05 2005 04:02 EDT
- struts log4j by jan vos on August 05 2005 02:58 EDT
-
struts log4j[ Go to top ]
- Posted by: Lars Vonk
- Posted on: August 04 2005 10:13 EDT
- in response to jan vos
Jan,
If you do not call the configureAndWatch() method, just name your file log4j.xml and put it anywhere on your classpath. Log4j will find it and there will be no need to call DOMConfigurator.configure() method in this case.
Or try to give the full path to the file e.g. /home/someoneshome/Log4jConfigFile.xml
Good luck -
struts log4j[ Go to top ]
- Posted by: jan vos
- Posted on: August 05 2005 02:58 EDT
- in response to Lars Vonk
Hi Lars,
Thank you. It does work this way.
I have 1 small question. My outputfile (mylog.txt) is directly written in the websphere application directory on my c:-drive (wich is logical because System.getProperties("user.dir") indicates that this is my current working directory). Is there a way to indicate another output directory in my xml-file or in a class-file, relative to my application (except from hardcoding the entire path)? -
struts log4j[ Go to top ]
- Posted by: Lars Vonk
- Posted on: August 05 2005 04:02 EDT
- in response to jan vos
In your log4j.xml file you can specify the output directory where your log is written.
<appender name="MyAppender" class="org.apache.log4j.RollingFileAppender">
<param name="File" value="logs/log4j.log"/>
</appender>
The "value" is relative to your working dir. In this example the logs will be written in: <workdir>/logs/log4j.log.
Was this what you where looking for? -
struts log4j[ Go to top ]
- Posted by: jan vos
- Posted on: August 05 2005 04:14 EDT
- in response to Lars Vonk
What you describe is what is happening now. Unfortunately the working directory is the websphere application directory and not my own written application. My application is even on another drive. I have hardcoded the complete path including the drive in my xml-file and this works perfectly. But when the application is going to a production environment I have no longer control. I don't even know where they are going to put my application. So a hardcoded path is hardly a good solution. But if this is the only posibility, I will use it because it this does work. -
struts log4j[ Go to top ]
- Posted by: Lars Vonk
- Posted on: August 05 2005 05:21 EDT
- in response to jan vos
Unfortunatly i think its the only way, since your application doesnot have a fixed path relative to the WebSphere Application Servers working directory.