how to control importing to db and File Using log4j
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   simon_zhao
Posted On:   Friday, December 13, 2002 07:44 AM

Now in a project,i have a request:some debug or warn information print to a file and some import info or warn information print to databases. If this project finished , i will set 'threshold=fatal' to appender of file ,but some debug information print to database.i think if i can use two properties for this question . But i want to use one properties file what named log4j.properites. I extends Logger Class for information imported to db use eg. // in MyLogger extends Logger public void append(String from,String subject,int level,String owner,String Description) { MDC.put("from",from); MDC.put("subject",subject); MDC.put("user&q   More>>

Now in a project,i have a request:some debug or warn information print to a
file and some import info or warn information print to databases. If this
project finished , i will set 'threshold=fatal' to appender of file ,but
some debug
information print to database.i think if i can use two properties for this
question .
But i want to use one properties file what named log4j.properites.
I extends Logger Class for information imported to db use eg.
// in MyLogger extends Logger
public void append(String from,String subject,int level,String owner,String
Description)
{
MDC.put("from",from);
MDC.put("subject",subject);
MDC.put("user",owner);
super.log(FQCN, Level.INFO, Description , null);
}

what can i do ?

log4j.properties


log4j.threshold=ALL
log4j.rootCategory=DEBUG, dest1,dest2
log4j.appender.dest1.threshold=fatal
log4j.appender.dest1=org.apache.log4j.RollingFileAppender
log4j.appender.dest1.File=debuginfo.log
log4j.appender.dest1.layout=org.apache.log4j.PatternLayout
log4j.appender.dest1.MaxFileSize=1000KB

log4j.appender.dest2.threshold=DEBUG
log4j.appender.dest2=org.apache.log4j.jdbc.JDBCAppender
log4j.appender.dest2.driver=org.gjt.mm.mysql.Driver
log4j.appender.dest2.URL=jdbc:mysql://localhost:3306/log
log4j.appender.dest2.User=test
log4j.appender.dest2.Password = test
log4j.appender.dest2.sql =insert into logtest
(from1,Subject,level,user,description,logDate)values('%X{from}','%X{subject}
','%p','%X{user}','%m','%d')
log4j.appender.dest2.layout=org.apache.log4j.PatternLayout

   <<Less
About | Sitemap | Contact