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

Similar Threads

Openning a File 3
Open a file with a href 5
log4j multiple appenders 3
log4j - outputting header twice for RollingFileAppender 3
log4j configuration and Applets 15
log4j: new file each time 1
log4j 11
log4j-1.2.8 0

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top