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.
timjowers - 02 Jul 2007 22:30 GMT
> 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
Arne Vajhøj - 12 Aug 2007 03:23 GMT
> 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