Issue in using log4j

Discussion in 'Java' started by arvind, Sep 5, 2008.

  1. arvind

    arvind Guest

    Hi All,

    I want to use logger in my application.

    I have AA.java:
    ****************************************************************************
    package A;

    import org.apache.log4j.Logger;


    public class AA {
    static Logger logger = Logger.getLogger(AA.class);

    public static void main(String[] args) {
    logger.info("Hi There");

    }

    }
    ****************************************************************************
    log4j.properties as:

    ### direct messages to file ###
    log4j.appender.file=org.apache.log4j.RollingFileAppender
    log4j.appender.file.File=C:\A.txt
    log4j.appender.file.layout=org.apache.log4j.PatternLayout
    log4j.appender.file.layout.ConversionPattern=%d{dd MMM yyyy
    HH:mm:ss,SSS}%5p %t %c{1}:%L - %m%n
    log4j.appender.file.MaxFileSize=5120KB
    # Archive log files (one backup file here)
    log4j.appender.file.MaxBackupIndex=1

    ****************************************************************************
    I have included log4j.jar in classpath.
    But I am getting following error:
    "log4j:WARN No appenders could be found for logger (A.AA).
    log4j:WARN Please initialize the log4j system properly."

    Please help me to solve this.........
    Thanks in anticipation.
     
    arvind, Sep 5, 2008
    #1
    1. Advertising

  2. arvind

    arvind Guest

    Thanks Lew ... for your valuable suggetions.

    On Sep 6, 6:50 am, Lew <> wrote:
    > arvindwrote:
    > > Hi All,

    >
    > > I want to use logger in my application.

    >
    > > I have AA.java:
    > > ***************************************************************************­*
    > > package A;

    >
    > Package names should comprise only lower-case letters:
    >
    >    package a;
    >
    >
    >
    >
    >
    > > import org.apache.log4j.Logger;

    >
    > > public class AA {
    > >    static Logger logger = Logger.getLogger(AA.class);

    >
    > >    public static void main(String[] args) {
    > >            logger.info("Hi There");

    >
    > >    }

    >
    > > }
    > > ***************************************************************************­*
    > > log4j.properties as:

    >
    > > ### direct messages to file ###
    > > log4j.appender.file=org.apache.log4j.RollingFileAppender
    > > log4j.appender.file.File=C:\A.txt

    >
    > You might want to get in the habit of using forward slashes.
    >
    > Java .properties files treat backslash as an escape character, so "C:\A.txt"
    > is not interpreted as you expect.
    >
    > > log4j.appender.file.layout=org.apache.log4j.PatternLayout
    > > log4j.appender.file.layout.ConversionPattern=%d{dd MMM yyyy
    > > HH:mm:ss,SSS}%5p %t %c{1}:%L - %m%n
    > > log4j.appender.file.MaxFileSize=5120KB
    > > # Archive log files (one backup file here)
    > > log4j.appender.file.MaxBackupIndex=1

    >
    > > ***************************************************************************­*
    > > I have included log4j.jar in classpath.
    > > But I am getting following error:
    > > "log4j:WARN No appenders could be found for logger (A.AA).
    > > log4j:WARN Please initialize the log4j system properly."

    >
    > <http://logging.apache.org/log4j/1.2/manual.html>
    >
    > your missing a rootLogger:
    >
    >    log4j.rootLogger=warn, file
    >
    > You can also change the logging level for different namespaces independently:
    >
    >    log4j.logger.a=DEBUG
    >
    > --
    > Lew- Hide quoted text -
    >
    > - Show quoted text -
     
    arvind, Sep 8, 2008
    #2
    1. Advertising

  3. arvind

    arvind Guest

    Thanks Lew ... for your valuable suggetions.

    On Sep 6, 6:50 am, Lew <> wrote:
    > arvindwrote:
    > > Hi All,

    >
    > > I want to use logger in my application.

    >
    > > I have AA.java:
    > > ***************************************************************************­*
    > > package A;

    >
    > Package names should comprise only lower-case letters:
    >
    >    package a;
    >
    >
    >
    >
    >
    > > import org.apache.log4j.Logger;

    >
    > > public class AA {
    > >    static Logger logger = Logger.getLogger(AA.class);

    >
    > >    public static void main(String[] args) {
    > >            logger.info("Hi There");

    >
    > >    }

    >
    > > }
    > > ***************************************************************************­*
    > > log4j.properties as:

    >
    > > ### direct messages to file ###
    > > log4j.appender.file=org.apache.log4j.RollingFileAppender
    > > log4j.appender.file.File=C:\A.txt

    >
    > You might want to get in the habit of using forward slashes.
    >
    > Java .properties files treat backslash as an escape character, so "C:\A.txt"
    > is not interpreted as you expect.
    >
    > > log4j.appender.file.layout=org.apache.log4j.PatternLayout
    > > log4j.appender.file.layout.ConversionPattern=%d{dd MMM yyyy
    > > HH:mm:ss,SSS}%5p %t %c{1}:%L - %m%n
    > > log4j.appender.file.MaxFileSize=5120KB
    > > # Archive log files (one backup file here)
    > > log4j.appender.file.MaxBackupIndex=1

    >
    > > ***************************************************************************­*
    > > I have included log4j.jar in classpath.
    > > But I am getting following error:
    > > "log4j:WARN No appenders could be found for logger (A.AA).
    > > log4j:WARN Please initialize the log4j system properly."

    >
    > <http://logging.apache.org/log4j/1.2/manual.html>
    >
    > your missing a rootLogger:
    >
    >    log4j.rootLogger=warn, file
    >
    > You can also change the logging level for different namespaces independently:
    >
    >    log4j.logger.a=DEBUG
    >
    > --
    > Lew- Hide quoted text -
    >
    > - Show quoted text -
     
    arvind, Sep 8, 2008
    #3
    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,779
    Alexandra Stehman
    Jan 19, 2004
  2. Alex Hunsley
    Replies:
    2
    Views:
    12,943
    =?ISO-8859-15?Q?Fr=E9d=E9ric_G=E9din?=
    May 28, 2004
  3. Rodolfo
    Replies:
    0
    Views:
    955
    Rodolfo
    Jul 12, 2004
  4. joes
    Replies:
    1
    Views:
    2,171
  5. Gianni Galore
    Replies:
    0
    Views:
    1,275
    Gianni Galore
    Sep 8, 2010
Loading...

Share This Page