Hmm, not understanding log4j properly :(

Discussion in 'Java' started by Pep, Oct 7, 2005.

  1. Pep

    Pep Guest

    I have these 2 lines of code in my test program

    private static final Category log = Category.getInstance("TEST");
    PropertyConfigurator.configure("TestOutputFile");

    and I thought after reading the documentation that this would open a output
    file called testOutputFile which log4j would then store the results in
    using the following line of code

    log.info(message);

    except that I get this error message

    log4j:ERROR Could not read configuration file [TestOutputFile].
    java.io.FileNotFoundException: TestOutputFile (No such file or directory)
    at java.io.FileInputStream.open(Native Method)
    at java.io.FileInputStream.<init>(FileInputStream.java:106)
    at java.io.FileInputStream.<init>(FileInputStream.java:66)
    at
    org.apache.log4j.PropertyConfigurator.doConfigure(PropertyConfigurator.java:297)
    at
    org.apache.log4j.PropertyConfigurator.configure(PropertyConfigurator.java:315)
    at uk.co.ticketweb.PSPserver.PSPserver.<init>(PSPserver.java:121)
    at uk.co.ticketweb.PSPserver.PSPserver.main(PSPserver.java:980)
    log4j:ERROR Ignoring configuration file [TestOutputFile].

    which indicates that

    PropertyConfigurator.configure("TestOutputFile");

    is actually looking to open this file for reading?

    I am now confused, I want to open a log file to write the output debug,
    info, warn and fatal messages to.

    Can anyone tell me what I need to do as I am somewhat confused by the
    documentation?

    TIA,
    Pep.
     
    Pep, Oct 7, 2005
    #1
    1. Advertising

  2. Pep

    Stefan Siegl Guest

    "Pep" <> wrote in message
    news:di5pjk$jpm$...
    > I have these 2 lines of code in my test program
    >
    > private static final Category log = Category.getInstance("TEST");
    > PropertyConfigurator.configure("TestOutputFile");
    >
    > and I thought after reading the documentation that this would open a

    output
    > file called testOutputFile which log4j would then store the results in
    > using the following line of code
    >
    > log.info(message);
    >
    > except that I get this error message

    [...]
    > which indicates that
    > PropertyConfigurator.configure("TestOutputFile");
    > is actually looking to open this file for reading?


    Right. This is because, PropertyConfigurator.configure() will try to setup
    the log4j system. As the documentation of the method (public static void
    configure(String configFilename)) suggests, the path that you have to
    provide is the path to the configuration file and not the path to the file
    you want your log information to be logged to. Log4j decouples the process
    of logging (e.g. log.info()) with the reaction to the logging (e.g. writing
    sth to a file). The reaction has to be defined within the configuration
    file. Log4j reads the configuration file and decides what should be done
    with logged information. For example you might have multiple appenders (e.g.
    one writing to a file and one to the console), with different layouts (e.g.
    the console only displays the time and the message, whereas the file logging
    should also provide the name of the class that logged the message).

    > Can anyone tell me what I need to do as I am somewhat confused by the
    > documentation?


    Try to define a properties file containing the configuration of log4j (here
    is a description: http://www.vipan.com/htdocs/log4jhelp.html). Let me know
    if you need more help

    hth,
    Stefan
     
    Stefan Siegl, Oct 7, 2005
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Alexandra Stehman

    eclipse, junit, log4j, & finding log4j.xml

    Alexandra Stehman, Jan 19, 2004, in forum: Java
    Replies:
    0
    Views:
    5,804
    Alexandra Stehman
    Jan 19, 2004
  2. Alex Hunsley
    Replies:
    2
    Views:
    12,989
    =?ISO-8859-15?Q?Fr=E9d=E9ric_G=E9din?=
    May 28, 2004
  3. Rodolfo
    Replies:
    0
    Views:
    967
    Rodolfo
    Jul 12, 2004
  4. joes
    Replies:
    1
    Views:
    2,216
  5. Gianni Galore
    Replies:
    0
    Views:
    1,292
    Gianni Galore
    Sep 8, 2010
Loading...

Share This Page