log4j and console in ANT/JUnit task

Discussion in 'Java' started by BlueDolphin, Oct 21, 2004.

  1. BlueDolphin

    BlueDolphin Guest

    Seems log4j is playing some magic...

    It always try to write debug info to console. If I set the rootLogger
    to INFO, then no info on both console and log file, if I set to DEBUG,
    message goes to both console and log....

    Confusing....
    I tried RollingFileAppender too....

    Thanks

    I have the following log4j.properties
    log4j.rootLogger = DEBUG, RRX

    #log4j.rootLogger = OFF, stdout

    log4j.appender.RRX=org.apache.log4j.FileAppender
    log4j.appender.RRX.File=MyRRX.log
    log4j.appender.RRX.layout=org.apache.log4j.PatternLayout
    log4j.appender.RRX.layout.ConversionPattern=%d %-5p %c - %m%n
    #log4j.appender.RRX.append=false
    BlueDolphin, Oct 21, 2004
    #1
    1. Advertising

  2. BlueDolphin

    Oscar kind Guest

    BlueDolphin <> wrote:
    > Seems log4j is playing some magic...
    >
    > It always try to write debug info to console. If I set the rootLogger
    > to INFO, then no info on both console and log file, if I set to DEBUG,
    > message goes to both console and log....


    No magic: you tell the logger to log something or not.

    What you want is to tell the appenders to disregard some of what the
    loggers log. An appender has a threshold as well.

    This is all documented BTW.


    --
    Oscar Kind http://home.hccnet.nl/okind/
    Software Developer for contact information, see website

    PGP Key fingerprint: 91F3 6C72 F465 5E98 C246 61D9 2C32 8E24 097B B4E2
    Oscar kind, Oct 21, 2004
    #2
    1. Advertising

  3. BlueDolphin

    jacksu Guest

    Oscar kind <> wrote in message news:<>...
    > BlueDolphin <> wrote:
    > > Seems log4j is playing some magic...
    > >
    > > It always try to write debug info to console. If I set the rootLogger
    > > to INFO, then no info on both console and log file, if I set to DEBUG,
    > > message goes to both console and log....

    >
    > No magic: you tell the logger to log something or not.
    >
    > What you want is to tell the appenders to disregard some of what the
    > loggers log. An appender has a threshold as well.
    >
    > This is all documented BTW.


    The point is, I am using FileAppender, which is suppose to only write
    to file, which it did, but no point for FileAppender to write to
    console at the same time, it is ConsoleAppender's job.....
    jacksu, Oct 22, 2004
    #3
  4. BlueDolphin

    Oscar kind Guest

    jacksu <> wrote:
    > The point is, I am using FileAppender, which is suppose to only write
    > to file, which it did, but no point for FileAppender to write to
    > console at the same time, it is ConsoleAppender's job.....


    My mistake, I thought it was just about the log levels.

    The same documentation is still very helpful: it states that you can use
    more than one appender for a logger. You specify all appenders and the
    threshold of the logger in the logger's definition, and the specific
    threshold with the appender:

    --- begin partial log4j configuration ---
    log4j.appender.Console=org.apache.log4j.ConsoleAppender
    log4j.appender.Console.Threshold=WARN
    # Some more properties...

    log4j.appender.Application=org.apache.log4j.RollingFileAppender
    log4j.appender.Application.Threshold=DEBUG
    # Some more properties...

    log4j.rootLogger=INFO, Console, Application
    ---- end partial log4j configuration ----

    Here, "info" and worse is logged to a file (even though the appender also
    writes for "debug"). Warnings and worse are also logged to the console.


    --
    Oscar Kind http://home.hccnet.nl/okind/
    Software Developer for contact information, see website

    PGP Key fingerprint: 91F3 6C72 F465 5E98 C246 61D9 2C32 8E24 097B B4E2
    Oscar kind, Oct 22, 2004
    #4
  5. BlueDolphin

    BlueDolphin Guest

    Oscar kind <> wrote in message news:<>...
    > jacksu <> wrote:
    > > The point is, I am using FileAppender, which is suppose to only write
    > > to file, which it did, but no point for FileAppender to write to
    > > console at the same time, it is ConsoleAppender's job.....

    >
    > My mistake, I thought it was just about the log levels.
    >
    > The same documentation is still very helpful: it states that you can use
    > more than one appender for a logger. You specify all appenders and the
    > threshold of the logger in the logger's definition, and the specific
    > threshold with the appender:
    >
    > --- begin partial log4j configuration ---
    > log4j.appender.Console=org.apache.log4j.ConsoleAppender
    > log4j.appender.Console.Threshold=WARN
    > # Some more properties...
    >
    > log4j.appender.Application=org.apache.log4j.RollingFileAppender
    > log4j.appender.Application.Threshold=DEBUG
    > # Some more properties...
    >
    > log4j.rootLogger=INFO, Console, Application
    > ---- end partial log4j configuration ----
    >
    > Here, "info" and worse is logged to a file (even though the appender also
    > writes for "debug"). Warnings and worse are also logged to the console.


    THanks for the information. I set the Threshold like you suggested,
    but I am still seeing the message printed to the console.

    BTW, I am using ANT's JUnit task to run my program, does that affected
    something?

    Thanks a lot.
    BlueDolphin, Oct 22, 2004
    #5
  6. BlueDolphin

    Oscar kind Guest

    BlueDolphin <> wrote:
    > BTW, I am using ANT's JUnit task to run my program, does that affected
    > something?


    No, but yes. You still need to make sure the loj4j configuration file is
    loaded. So in this regard nothing changes.

    But, the way the log4j configuration file is loaded now may differ from
    the way you usually do this. So it is something to verify again.


    --
    Oscar Kind http://home.hccnet.nl/okind/
    Software Developer for contact information, see website

    PGP Key fingerprint: 91F3 6C72 F465 5E98 C246 61D9 2C32 8E24 097B B4E2
    Oscar kind, Oct 22, 2004
    #6
  7. BlueDolphin

    BlueDolphin Guest

    Oscar kind <> wrote in message news:<>...
    > BlueDolphin <> wrote:
    > > BTW, I am using ANT's JUnit task to run my program, does that affected
    > > something?

    >
    > No, but yes. You still need to make sure the loj4j configuration file is
    > loaded. So in this regard nothing changes.
    >
    > But, the way the log4j configuration file is loaded now may differ from
    > the way you usually do this. So it is something to verify again.


    Sure, I believe the log4j in ant is different, but how to work on it
    properly?

    It reads the root.logger settings from the logger.properties. Seems
    just have one default consoleappender, silently associate with the
    root.logger's setting...

    Any idea to split the relation?

    Thanks
    BlueDolphin, Oct 23, 2004
    #7
    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. Scout
    Replies:
    0
    Views:
    520
    Scout
    Aug 4, 2003
  2. Christopher Blunck

    Re: Junit Ant Task

    Christopher Blunck, Aug 13, 2003, in forum: Java
    Replies:
    1
    Views:
    598
    Scout
    Aug 19, 2003
  3. Alexandra Stehman

    eclipse, junit, log4j, & finding log4j.xml

    Alexandra Stehman, Jan 19, 2004, in forum: Java
    Replies:
    0
    Views:
    5,773
    Alexandra Stehman
    Jan 19, 2004
  4. bugbear
    Replies:
    4
    Views:
    1,831
    bugbear
    Jan 28, 2004
  5. stixwix

    ant junit task

    stixwix, Nov 29, 2005, in forum: Java
    Replies:
    0
    Views:
    703
    stixwix
    Nov 29, 2005
Loading...

Share This Page