On Fri, Jul 6, 2012 at 4:02 AM, Martinus Martinus <martinus...@gmail.com>wrote:
> Hi, > > What is the equivalent programmatical java code for below logback.xml > configuration : > > <configuration> > > <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> > <!-- encoders are assigned the type > ch.qos.logback.classic.encoder.PatternLayoutEncoder > by default --> > <encoder> > <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger - > %msg%n</pattern> > </encoder> > </appender> > > <appender name="SYSLOG" > class="ch.qos.logback.classic.net.SyslogAppender"> > * <syslogHost>myhost</syslogHost>* > * <facility>USER</facility>* > * <suffixPattern>[%thread] %logger *%msg</suffixPattern> > </appender> > > <root level="debug"> > <appender-ref ref="SYSLOG"/> > <appender-ref ref="STDOUT"/> > </root> > </configuration> > > Thanks. Hi Martinus, This doesn't directly answer your question, but it provides a solution if your goal is to configure logback from code instead of logback.xml... You can load the configuration XML into a string and feed that to a JoranConfigurator, as in the example below. Btw, please refrain from posting the same question repeatedly. :) Hope that helps, Tony static private final String LOGBACK_XML = "<configuration>" + " " + " <appender name='STDOUT' class='ch.qos.logback.core.ConsoleAppender'> " + " <!-- encoders are assigned the type ch.qos.logback.classic.encoder.PatternLayoutEncoder" + " by default --> " + " <encoder> " + " <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger - %msg%n</pattern> " + " </encoder> " + " </appender> " + " " + " <appender name='SYSLOG' class='ch.qos.logback.classic.net.SyslogAppender'> " + " <syslogHost>myhost</syslogHost> " + " <facility>USER</facility> " + " <suffixPattern>[%thread] %logger %msg</suffixPattern> " + " </appender> " + " " + " <root level='debug'> " + " <appender-ref ref='SYSLOG'/> " + " <appender-ref ref='STDOUT'/> " + " </root> " + "</configuration> " ; static private void configureLogback() { BufferedInputStream xmlStream = new BufferedInputStream(new ByteArrayInputStream(LOGBACK_XML.getBytes())); LoggerContext context = (LoggerContext)LoggerFactory.getILoggerFactory(); context.reset(); // override default config JoranConfigurator joran = new JoranConfigurator(); joran.setContext(context); try { joran.doConfigure(xmlStream); StatusPrinter.printInCaseOfErrorsOrWarnings(context); } catch (JoranException e) { e.printStackTrace(); } }
_______________________________________________ Logback-user mailing list Logback-user@qos.ch http://mailman.qos.ch/mailman/listinfo/logback-user