Hi Tony,<br><br>Thanks for your answer. Is there a way to make my application log to be save in separate syslog file? Like with name MyApps. Sorry from posting the same question repeatedly, because I just join this group and I thought my first email didn't reach this group mail.<br>
<br>Thanks.<br><br><div class="gmail_quote">On Fri, Jul 6, 2012 at 7:20 PM, Tony Trinh <span dir="ltr"><<a href="mailto:tony19@gmail.com" target="_blank">tony19@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="gmail_quote"><div><div class="h5">On Fri, Jul 6, 2012 at 4:02 AM, Martinus Martinus <span dir="ltr"><<a href="mailto:martinus787@gmail.com" target="_blank">martinus787@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hi,<br><br>What is the equivalent programmatical java code for below logback.xml configuration :<br><br><blockquote>
<span style="font-family:"Courier New",Courier,monospace"><configuration></span><br>
<br>
<span style="font-family:"Courier New",Courier,monospace"> <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"></span><br>
<span style="font-family:"Courier New",Courier,monospace"> <!-- encoders are assigned the type ch.qos.logback.classic.encoder.PatternLayoutEncoder </span><br>
<span style="font-family:"Courier New",Courier,monospace"> by default --></span><br>
<span style="font-family:"Courier New",Courier,monospace"> <encoder></span><br>
<span style="font-family:"Courier New",Courier,monospace"> <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger - %msg%n</pattern></span><br>
<span style="font-family:"Courier New",Courier,monospace"> </encoder></span><br>
<span style="font-family:"Courier New",Courier,monospace"> </appender></span><br>
<br>
<span style="font-family:"Courier New",Courier,monospace"> <appender name="SYSLOG" class="ch.qos.logback.classic.net.SyslogAppender"></span><br>
<b><span style="font-family:"Courier New",Courier,monospace"> <syslogHost>myhost</syslogHost></span></b><br>
<b><span style="font-family:"Courier New",Courier,monospace"> <facility>USER</facility></span></b><br>
<span style="font-family:"Courier New",Courier,monospace"><b> <suffixPattern>[%thread] %logger </b>%msg</suffixPattern></span><br>
<span style="font-family:"Courier New",Courier,monospace"> </appender></span><br>
<br>
<span style="font-family:"Courier New",Courier,monospace"> <root level="debug"></span><br>
<span style="font-family:"Courier New",Courier,monospace"> <appender-ref ref="SYSLOG"/></span><br>
<span style="font-family:"Courier New",Courier,monospace"> <appender-ref ref="STDOUT"/></span><br>
<span style="font-family:"Courier New",Courier,monospace"> </root></span><br>
<span style="font-family:"Courier New",Courier,monospace"></configuration></span> </blockquote>Thanks. </blockquote><div><br></div></div></div><div>Hi Martinus,</div><div><br></div><div>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. </div>
<div><br></div><div>Btw, please refrain from posting the same question repeatedly. :)</div><div><br></div><div>Hope that helps,</div><div>Tony</div><div><br></div><div><div><span style="white-space:pre-wrap"> </span><font face="courier new, monospace">static private final String LOGBACK_XML =</font></div>
<div><font face="courier new, monospace"><span style="white-space:pre-wrap"> </span>"<configuration>" +</font></div><div><font face="courier new, monospace"><span style="white-space:pre-wrap"> </span>" " +</font></div>
<div><font face="courier new, monospace"><span style="white-space:pre-wrap"> </span>" <appender name='STDOUT' class='ch.qos.logback.core.ConsoleAppender'> " +</font></div>
<div><font face="courier new, monospace"><span style="white-space:pre-wrap"> </span>" <!-- encoders are assigned the type ch.qos.logback.classic.encoder.PatternLayoutEncoder" +</font></div>
<div><font face="courier new, monospace"><span style="white-space:pre-wrap"> </span>" by default --> " +</font></div>
<div><font face="courier new, monospace"><span style="white-space:pre-wrap"> </span>" <encoder> " +</font></div>
<div><font face="courier new, monospace"><span style="white-space:pre-wrap"> </span>" <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger - %msg%n</pattern> " +</font></div>
<div><font face="courier new, monospace"><span style="white-space:pre-wrap"> </span>" </encoder> " +</font></div>
<div><font face="courier new, monospace"><span style="white-space:pre-wrap"> </span>" </appender> " +</font></div>
<div><font face="courier new, monospace"><span style="white-space:pre-wrap"> </span>" " +</font></div>
<div><font face="courier new, monospace"><span style="white-space:pre-wrap"> </span>" <appender name='SYSLOG' class='ch.qos.logback.classic.net.SyslogAppender'> " +</font></div>
<div><font face="courier new, monospace"><span style="white-space:pre-wrap"> </span>" <syslogHost>myhost</syslogHost> " +</font></div>
<div><font face="courier new, monospace"><span style="white-space:pre-wrap"> </span>" <facility>USER</facility> " +</font></div>
<div><font face="courier new, monospace"><span style="white-space:pre-wrap"> </span>" <suffixPattern>[%thread] %logger %msg</suffixPattern> " +</font></div>
<div><font face="courier new, monospace"><span style="white-space:pre-wrap"> </span>" </appender> " +</font></div>
<div><font face="courier new, monospace"><span style="white-space:pre-wrap"> </span>" " +</font></div>
<div><font face="courier new, monospace"><span style="white-space:pre-wrap"> </span>" <root level='debug'> " +</font></div>
<div><font face="courier new, monospace"><span style="white-space:pre-wrap"> </span>" <appender-ref ref='SYSLOG'/> " +</font></div>
<div><font face="courier new, monospace"><span style="white-space:pre-wrap"> </span>" <appender-ref ref='STDOUT'/> " +</font></div>
<div><font face="courier new, monospace"><span style="white-space:pre-wrap"> </span>" </root> " +</font></div>
<div><font face="courier new, monospace"><span style="white-space:pre-wrap"> </span>"</configuration> " </font></div>
<div><font face="courier new, monospace"><span style="white-space:pre-wrap"> </span>;</font></div><div><span style="white-space:pre-wrap"><font face="courier new, monospace"> </font></span></div>
<div><font face="courier new, monospace"> static private void configureLogback() {</font></div><div><font face="courier new, monospace"> BufferedInputStream xmlStream = new BufferedInputStream(new ByteArrayInputStream(LOGBACK_XML.getBytes()));</font></div>
<div><font face="courier new, monospace"> </font></div><div><font face="courier new, monospace"> LoggerContext context = (LoggerContext)LoggerFactory.getILoggerFactory();</font></div><div><font face="courier new, monospace"> context.reset(); // override default config</font></div>
<div><font face="courier new, monospace"> JoranConfigurator joran = new JoranConfigurator();</font></div><div><font face="courier new, monospace"> joran.setContext(context);</font></div><div><font face="courier new, monospace"> try {</font></div>
<div><font face="courier new, monospace"> joran.doConfigure(xmlStream);</font></div><div><font face="courier new, monospace"> StatusPrinter.printInCaseOfErrorsOrWarnings(context);</font></div><div><font face="courier new, monospace"> } catch (JoranException e) {</font></div>
<div><span style="font-family:'courier new',monospace"> e.printStackTrace();</span></div><div><font face="courier new, monospace"> }</font></div><div><font face="courier new, monospace"> }</font></div>
</div><div><br></div></div>
<br>_______________________________________________<br>
Logback-user mailing list<br>
<a href="mailto:Logback-user@qos.ch">Logback-user@qos.ch</a><br>
<a href="http://mailman.qos.ch/mailman/listinfo/logback-user" target="_blank">http://mailman.qos.ch/mailman/listinfo/logback-user</a><br></blockquote></div><br>