2012-03-22 124 views
0

我使用Logback框架v1.0.1来执行日志记录。我想知道如何将日志消息附加到java中的outputstream。Logback:将日志消息附加到输出流appender

我想将日志消息格式化为key = value对最后,我想将格式化的日志消息作为输出流。我检索记录器实例并在调试级别记录消息。

ch.qos.logback.classic.Logger logger = (ch.qos.logback.classic.Logger)  LoggerFactory.getLogger("SplunkSearch.SplunkLogger"); 
    logger.info("wrap = true, setValue = false,"); 
    logger.debug("wrap = true, setValue = false,"); 


The logback.xml configuration file is as follows : 

<?xml version="1.0" encoding="UTF-8"?> 
<configuration debug="true"> 

<timestamp key="bySecond" datePattern="yyyyMMdd'T'HHmmss"   timeReference="contextBirth"/> 

<contextName>splunksearchcontext</contextName> 

<appender name="stdout" class="ch.qos.logback.core.ConsoleAppender"> 
    <Target>System.out</Target> 
    <encoder> 
    <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern> 
    </encoder> 
    </appender> 

    <appender name= "outputstream" class="ch.qos.logback.core.OutputStreamAppender"> 
    <encoder> 
    <pattern></pattern> 
</encoder> 
</appender> 

<root level="debug"> 
<appender-ref ref="stdout"/> 
<appender-ref ref="outputstream" /> 
    </root> 
</configuration> 

当我运行时,输出如下。

我在状态消息中看到了这一行,这是有点错误。没有输出流设置。

15:07:19399 |·ERROR在ch.qos.logback.core.OutputStreamAppender [OutputStream中] - 一个名为 “OutputStream中的” 附加器没有
输出流的组。

15:07:19.414 [主要] INFO SplunkSearch.SplunkLogger - 涡卷=真,的setValue =假,

15:07:19.430 [主要] DEBUG SplunkSearch.SplunkLogger - 涡卷=真,的setValue =假,

回答

0

它表示“没有为名为”outputstream“的appender设置输出流。”你定义了一个appender,但不是输出流。我不知道在哪里写信息。

logback手册说你不应该直接使用outputstream appender。从手册中,我也没有找到任何方法将输出流配置到这个appender中。

如果你真的想使用它,我认为唯一的方法就是将它添加到你的程序中。