Menu

Using custom log4j.properties file

Help
Stopgap
2007-04-19
2013-04-25
  • Stopgap

    Stopgap - 2007-04-19

    Hello,

    I read elsewhere in this forum that one way to override the log4j.properties file that is packaged in jameleon-core.jar is to create my own log4j.properties file and put it "before" the jameleon-core version in my classpath. I'd like to use a custom log4j.properties file without resorting to using the jameleon source files. I've tried a few things, but none of them seem to be working. Can you give me some instructions on how to do this? Is it even possible?

    Here's one thing I tried:

    1) Create log4j.properties as follows:
    log4j.rootLogger=INFO, STDOUT
    log4j.logger.net.sf.jameleon=DEBUG, J2, J1, SLO

    log4j.appender.STDOUT=org.apache.log4j.ConsoleAppender
    log4j.appender.STDOUT.Threshold=FATAL
    log4j.appender.STDOUT.layout=org.apache.log4j.SimpleLayout

    log4j.appender.J1=org.apache.log4j.FileAppender
    log4j.appender.J1.Threshold=INFO
    log4j.appender.J1.Append=true
    log4j.appender.J1.Encoding=UTF-8
    log4j.appender.J1.File=TestResults2.html
    log4j.appender.J1.layout=net.sf.jameleon.logging.JameleonHTMLLayout
    log4j.appender.J1.layout.Title=Jameleon Test Case Results

    log4j.appender.SLO=org.apache.log4j.ConsoleAppender
    log4j.appender.SLO.Threshold=INFO
    log4j.appender.SLO.layout=net.sf.jameleon.logging.JameleonSimpleLayout

    log4j.appender.J2=org.apache.log4j.FileAppender
    log4j.appender.J2.Append=false
    log4j.appender.J2.Encoding=UTF-8
    log4j.appender.J2.File=TestResults2.xml
    log4j.appender.J2.layout=net.sf.jameleon.logging.JameleonXMLLayout

    2) Place the new log4j.properties file in the directory jameleon-test-suite\log
    3) Adjust the "base.classpath" setting in build.xml to

      <path id="base.classpath">
        <pathelement location="${log.dir}"/>
        <fileset dir="${lib.dir}">
          <include name="*.jar"/>
        </fileset>
        <pathelement location="${lib.dir}"/>
      </path>

    where ${log.dir} is the log directory from 2)

    4) Run build.bat
    5) Run jameleon.bat and run a test.

    In this example, I want TestResults.html and TestResults.xml to be exactly the same, but with the names TestResults2.html and TestResults2.xml respectively, but aside from being created initially, they are not populated as the test runs. TestResults.*ml are created insteadl. Ideally I'll be able to override more settings once I get this to work.

    Thanks.

     
    • Stopgap

      Stopgap - 2007-04-19

      A solution I've found that seems to work: open up jameleon-core.jar, and replace the log4j.properties file with my own. If there's a way to do it without modifying jameleon-core.jar, I'd still be interested to hear it, but this will do for my purposes.

       
      • Christian Hargraves

        Currently, that's the only way around this.

         
      • Sannie Kwakman

        Sannie Kwakman - 2007-04-20

        I'm running Jameleon through a separate homemade jameleonlauncher class (using the Jameleon api instead of batchfiles). This class is contained in a .jar file which also contains it's own log4j.properties file, at the root level of the .jar's filestructure. And this file seems to 'override' the one in jameleon-core.jar. This way I can change log4j properties without changing the one in jameleon-core.jar.

        Although this example is fairly specific to my usage of Jameleon, it might be enough to place log4j.properties inside the 'root' of your java project..?

         

Log in to post a comment.