在我的project.clj
:dependencies
,我有:
[org.clojure/tools.logging "0.2.6"]
[ch.qos.logback/logback-classic "1.0.11"]
[net.logstash.logback/logstash-logback-encoder "1.0"]
在我的core.clj
,我有:
(clojure.tools.logging/info "both stdout and stash")
(clojure.tools.logging/log "stash" :info nil "only stash?")
在我的资源路径上,我有一个文件logback.xml
,我在其中定义了两个附加程序stdout
,并且stash
都附加到根目录:
<?xml version="1.0" encoding="UTF-8"?>
<configuration debug="false">
<appender name="stdout" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>
<appender name="stash" class="ch.qos.logback.core.FileAppender">
<file>example.log</file>
<encoder class="net.logstash.logback.encoder.LogstashEncoder" />
</appender>
<root level="all">
<appender-ref ref="stash" />
<appender-ref ref="stdout" />
</root>
</configuration>
当我运行我的程序时,我看到以下(期望的)输出example.log
:
{"@timestamp":"2013-04-10T12:42:16-04:00","@message":"both stdout and stash","@fields":{"logger_name":"scheduler.core","thread_name":"main","level":"INFO","level_value":20000}}
{"@timestamp":"2013-04-10T12:42:16-04:00","@message":"only stash?","@fields":{"logger_name":"stash","thread_name":"main","level":"INFO","level_value":20000}}
但是,我看到以下两行都打印到标准输出——我只想看到第一行:
12:42:16.573 [main] INFO scheduler.core - both stdout and stash
12:42:16.641 [main] INFO stash - only stash?
如何选择使用哪个 appender 登录clojure.tools.logging
?具体来说,两者都stdout
附加stash
在根目录下,我怎样才能只登录到stash
?