Hi Tony,
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.
Thanks.
On Fri, Jul 6, 2012 at 4:02 AM, Martinus Martinus <martinus787@gmail.com> wrote:Hi,
What is the equivalent programmatical java code for below logback.xml configuration :<configuration>Thanks.
<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>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,Tonystatic 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 configJoranConfigurator 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