[logback-dev] programmatic configuration

Cheenu cheenu321 at gmail.com
Sat Feb 28 06:45:38 CET 2009


Is there a way to programmatically configure logback without using any  
config file at all.

I saw http://logback.qos.ch/xref/chapter3/MyApp3.html
and that is still configuring using a config file.

Use-case: multiple invocations of same app (with same classpath) needs  
to
log to different file appenders, possibly with different patterns.
Hence, need facility to dynamically configure these at runtime (at  
startup).

In log4j, I can do this using
Logger logger = Logger.getLogger("abc.xyz");
FileAppender fileAppender = (FileAppender)logger.getAppender("file");
if(fileAppender != null) {
   fileAppender.setFile("new.log");
   fileAppender.setLayout(new PatternLayout("%d{ISO8601} %5p %t [%c: 
%L] %m%n"));
   fileAppender.activateOptions();
}

How do I do similar thing in logback?

Thanks
Cheenu

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://qos.ch/pipermail/logback-dev/attachments/20090227/db4f896f/attachment.htm>


More information about the logback-dev mailing list