struts log4j


EJB design: struts log4j

  1. struts log4j (5 messages)

    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.


    Threaded Messages (5)

  2. struts log4j[ Go to top ]


    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
  3. struts log4j[ Go to top ]

    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)?
  4. struts log4j[ Go to top ]

    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"/>

    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?
  5. struts log4j[ Go to top ]

    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.
  6. struts log4j[ Go to top ]

    Unfortunatly i think its the only way, since your application doesnot have a fixed path relative to the WebSphere Application Servers working directory.