dcsimg
concurrent problem---DailyRollingFileAppender
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   qiqi_bawanglong
Posted On:   Monday, December 23, 2002 02:20 AM

Hi, all Thanks in advance for your attention. Log4j is new to me, i think perhaps i can get some help from you. Thanks again! i want to use 'DailyRollingFileAppender' to create log files periodically. as you can see in the attachment, 'loggerManager' wraps logging operations. It configures log4j by reading a configuration file in properties format, 'mylogger1' and 'mylogger2' are two files invoking loggerManager's doIt() method to write log messages. When this two process both try to copy the old 'minite.log' file to 'minite.log.yyyy-mm-dd-hh-mm' file, there comes a cocurrent problem. i don't know how to handle this prolem, could you give me some sugge   More>>

Hi, all

Thanks in advance for your attention.

Log4j is new to me, i think perhaps i can get some help from you. Thanks again!

i want to use 'DailyRollingFileAppender' to create log files periodically.

as you can see in the attachment, 'loggerManager' wraps
logging operations. It configures log4j by reading a configuration file in properties format,

'mylogger1' and 'mylogger2' are two files invoking
loggerManager's doIt() method to write log messages.

When this two process both try to copy the old 'minite.log'
file to 'minite.log.yyyy-mm-dd-hh-mm' file, there comes a cocurrent problem.

i don't know how to handle this prolem, could you give me some suggestions?


Another question :

i read the log4j document and have a basic idea that i can log to the DB using JDBCAppender.

i want to know if i can write to some specific columns(such
as source, destination, status), not only the
properties defined in the log4j (such as priority, thread, time...)

if anyone can tell me more detailed information, i would be very appreciated.


B.R.

-bawanglongqiqi


===========================================================

loggerManager.java:

---------------------------------------------------

import org.apache.log4j.Logger;

import org.apache.log4j.PropertyConfigurator;

import org.apache.log4j.xml.DOMConfigurator;


public class loggerManager {

//private static Logger logger;

private org.apache.log4j.Category logger;

private static loggerManager loggermanager = new loggerManager();


private loggerManager() {

String configfile = "periodic1.properties";

PropertyConfigurator.configure(configfile);


}

public static loggerManager getManager() {

return loggermanager;

}



public synchronized void doIt(Class classfile) {




//Logger logger = Logger.getLogger(Rolling.class);

//logger = Logger.getLogger(classfile);

logger = org.apache.log4j.Category.getInstance(classfile);

int i = 0;

while(true) {

logger.debug("This message number: " + (i++) );

try {

Thread.currentThread().sleep(12000);

}

catch (Exception e) {}

}

}


}
===========================================================

mylogger1.java:

---------------------------------------------------


public class mylogger1 {


public static void main(String[] args) {

///if(args.length != 1)

/// usage("Wrong number of arguments.");

//mylogger1 logger1 = new mylogger1();

Class loggerClass1 = mylogger1.class;

//String configfile = args[0];

loggerManager loggermanager = loggerManager.getManager();

loggermanager.doIt(loggerClass1);


}


static void usage(String msg) {

System.err.println(msg);

System.err.println(

"Usage: java "+mylogger1.class.getName()+"
configFile
"+

" configFile a log4j configuration file, either in properties "+

" or XML format. XML files must have a '.xml'
extension.");

System.exit(1);

}


}

===========================================================

mylogger2.java:

---------------------------------------------------

public class mylogger2 {


public static void main(String[] args) {

///if(args.length != 1)

/// usage("Wrong number of arguments.");

//mylogger1 logger1 = new mylogger1();

Class loggerClass2 = mylogger2.class;

//String configfile = args[0];

loggerManager loggermanager = loggerManager.getManager();

loggermanager.doIt(loggerClass2);


}


static void usage(String msg) {

System.err.println(msg);

System.err.println(

"Usage: java "+mylogger2.class.getName()+"
configFile
"+
" configFile a log4j configuration file, either in properties "+

" or XML format. XML files must have a '.xml'
extension.");

System.exit(1);

}


}

===========================================================

periodic1.properties:

---------------------------------------------------


# Sample usage DaillyRolingAppender that rolls every minute.


log4j.rootLogger=debug, ROLL

log4j.appender.ROLL=org.apache.log4j.DailyRollingFileAppender

log4j.appender.ROLL.File=log/minute.log

log4j.appender.ROLL.DatePattern=.yyyy-MM-dd-HH-mm

log4j.appender.ROLL.layout=org.apache.log4j.PatternLayout

log4j.appender.ROLL.layout.ConversionPattern=%d %-5p %c - %m%n

   <<Less
About | Sitemap | Contact