logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Ravinder Singh Ghai" <gha...@gmail.com>
Subject Need help with database logging for JDK 1.1.8
Date Sun, 07 Oct 2007 13:25:39 GMT
 Dear friends

Need help with logging logs into database using JDK 1.1.8. Please read
through my .java and properties file attached below. Also please note this
application works well with JDK 1.5.

I get runtime error while parsing the properties file (just before
commencing parsing for database appender part), saying "Can't find class
TestJDBCLogging"

I've also tried setting classpath to C:\log4j\HelloWorld inside System
Environment Variables...but no luck. Moreover I've tried using various
versions of log4j jars starting from ver. 1.2.1 to 1.2.7 but still same
situation...however, using ver 1.2.7 onwards gives compile-time errors on
JDK 1.1.8.


## log4j.properties file ##

#### Use three appenders - log to console, log to a file and log to the
database
log4j.rootCategory=debug, stdout, Roll, CRSDBAPPENDER
log4j.debug=true

#### stdout - First appender writes to console
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%x %d{HH:mm:ss,SSS} %5p [%t]
(%c:%-4L %M) - %m%n

#### Roll - Second appender writes to a file
log4j.appender.Roll=org.apache.log4j.RollingFileAppender
#log4j.appender.Roll.File=${InstanceName}.log
log4j.appender.Roll.File=HelloWorld.log
log4j.appender.Roll.MaxFileSize=20KB
log4j.appender.Roll.MaxBackupIndex=10
log4j.appender.Roll.layout=org.apache.log4j.PatternLayout
log4j.appender.Roll.layout.ConversionPattern=%x %d{yyyy.MM.dd HH:mm:ss,SSS}
%5p [%t] (%c:%-4L %M) - %m%n

#### CRSDBAPPENDER - third appender writes to the database
log4j.appender.CRSDBAPPENDER=org.apache.log4j.jdbc.JDBCAppender
log4j.appender.CRSDBAPPENDER.Driver=com.microsoft.jdbc.sqlserver.SQLServerDriver
log4j.appender.CRSDBAPPENDER.URL=jdbc:sqlserver://arncorp15:1433
;DatabaseName=LOG
log4j.appender.CRSDBAPPENDER.user=test
log4j.appender.CRSDBAPPENDER.password=test123
log4j.appender.CRSDBAPPENDER.layout=org.apache.log4j.PatternLayout
log4j.appender.CRSDBAPPENDER.sql=INSERT INTO LOG (computername,
crsservername, logtime, loglevel, threadname, filename, linenumber, logtext)
VALUES ('Ravinder', 'ARNCORP15', '%d', '%p', '%t', '%F', '%L', '%m')

##################################################################

## TestJDBCLogging.java file ##

import org.apache.log4j.*;

public class TestJDBCLogging {

    static Category cat = Category.getInstance(TestJDBCLogging.class.getName
());
    // static Logger log = Logger.getLogger(TestJDBCLogging.class.getName
());

    public static void main(String[] args) {
         try{
            // Now, try a few logging methods
            MDC.put("myComputerName", "Ravinder");
            MDC.put("crsServerName", "ARNDEV01");
            cat.debug("Start of main()");
            cat.info("Just testing a log message \" with priority set to
INFO");
            cat.warn("Just testing a log; message \\with priority set to
WARN");
            cat.error("Just testing a log message; with priority set to
ERROR");
            cat.fatal("Just testing a log message / with priority set to
FATAL");
        }
        catch(Exception e){
            e.printStackTrace();
        }
     }
}

*Directory structure ->*

*Location of .java, .class and properties file -*
C:\log4j\HelloWorld

*Location of library jar files (log4j-1.2.7 and jdbc driver etc) -*
C:\log4j\HelloWorld\lib

Looking forward to your replies...

Ravi Singh

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message