log4j - openning a new file

E

ER

Hi,

I need to open a new log file in a specific location in the code, how
can I do that?
Log file size and number of records are unknown so I cannot use this
information.
 
T

timjowers

Hi,

I need to open a new log file in a specific location in the code, how
can I do that?
Log file size and number of records are unknown so I cannot use this
information.

Not sure about log4j but probably the same as Java logging. You can
create a new handler at any time. That handler can be a file handler.
Is something like this waht you need?
FileHandler handler = new FileHandler("another.log",
appendToFile);
Logger logger = Logger.getLogger("examples.LogExample");
logger.addHandler(handler);
Best,
TimJowers
 
?

=?ISO-8859-1?Q?Arne_Vajh=F8j?=

ER said:
I need to open a new log file in a specific location in the code, how
can I do that?
Log file size and number of records are unknown so I cannot use this
information.

Simple example:

log4j.category.test = debug, logfile
log4j.appender.logfile.threshold = debug
log4j.appender.logfile = org.apache.log4j.FileAppender
log4j.appender.logfile.file = C:/first.log
log4j.appender.logfile.layout = org.apache.log4j.PatternLayout
log4j.appender.logfile.layout.ConversionPattern = %d %C %M %p: %m%n

import org.apache.log4j.*;

public class SwitchFile {
public static void main(String[] args) {
PropertyConfigurator.configure("C:\\log4j.properties");
Logger log = Logger.getLogger("test");
log.info("1");
log.info("2");
FileAppender fa = (FileAppender)log.getAppender("logfile");
fa.setFile("C:/second.log");
fa.activateOptions();
log.info("3");
log.info("4");
}
}

Arne
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,432
Messages
2,571,681
Members
48,796
Latest member
Greg L.

Latest Threads

Top