问题描述
我正在尝试流式传输基本的Hello World Log消息,以显示Log4J2中的Chainsaw.我不在乎它是否使用" zeroconf",我只想要有效的东西.我知道我的测试程序正在记录消息,因为它们在控制台上显示,我知道它正在找到我的配置文件,因为我可以更改在控制台中打印的消息的格式,但这就是我所知道的.
我的配置文件(包含各种失败的猜测):
<?xml version="1.0" encoding="UTF-8"?> <configuration advertiser="org.apache.logging.log4j.core.net.MulticastDNSAdvertiser"> <appenders> <Console name="Console" target="SYSTEM_OUT"> <PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %m%n"/> </Console> <File name="testFile" fileName="logs/test.log" bufferedIO="false" advertiseURI="file://localhost/home/matt/code/ade/logs/test.log" advertise="true"> <XMLLayout /> </File> <SocketAppender name="socketTest" host="localhost" immediateFlush="true" port="4560" protocol="TCP" advertiseURI="http://localhost" advertise="true"> <XMLLayout /> </SocketAppender> </appenders> <loggers> <root level="TRACE"> <appender-ref ref="Console"/> <appender-ref ref="testFile"/> <appender-ref ref="socketTest"/> </root> </loggers> </configuration>
我已经尝试了各种组合:包括jmdns.jar在类路径上,在各个方面重新启动电锯,却感到沮丧,但没有任何帮助.
有什么想法?
编辑:我弄清楚了为什么它无法读取我保存到磁盘的日志文件(我没有使用Xmllayout),所以我已经更新了问题,以反映我现在只需要使流媒体工作.
推荐答案
'广告商'使用log4j2插件机制,因此您必须在配置中在广告商上定义的"名称" - 不是完全合格的类名称.
log4j2广告机制当前支持Fileappender和socketAppender的广告.但是,电锯仅支持发现log4j2 fileappender的,这些fileappender asteral layaut宣传. Xmllayout支持将在不久的将来出现.
必须使用Chainsaw的最新开发人员快照,以利用Log4J2的广告商机制. Chainsaw Tarball和DMG可在以下网址提供: http://people.apache.org/cathe.org/~sdeboy//p>
Chainsaw将发现广告的滤清器配置和解析(以及如果您获得最新的电锯开发人员构建)日志文件 - 无需链锯配置. 注意,您需要使用模式layout,并且JMDN必须使用此Appender配置. 这是一个示例log4j2 -appender-配置,它将宣传fileAppender配置: 启动使用Appender的应用程序后
配置,在电锯中打开" Zeroconf"选项卡. 您应该看到带有Appender的名称的一行(假设您添加了
使用fileappender的jmdns到该应用程序的classpath
配置). 如果您想始终启动电锯
如果可用,则使用此配置. 接下来,双击
在带有Appender名称和Chainsaw的行上,将开始解析和尾随日志文件. 文件appender中提供的广告网址
配置必须可以通过网络访问网络锯(看起来您正在工作
用电锯和您的fileappender在本地,因此file:///路径将
工作正常 - 请注意三个斜线). 电锯,如果每个字段周围都有定界数 - 方括号,破折号等,那么只要您在划界的字段中不存在该字符.<?xml version="1.0" encoding="UTF-8"?>
<configuration advertiser="multicastdns">
<appenders>
<Console name="Console" target="SYSTEM_OUT">
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %m%n"/>
</Console>
<File name="testFile" fileName="logs/test.log" bufferedIO="false" advertiseURI="file:///localhost/home/matt/code/ade/logs/test.log" advertise="true">
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %m%n"/>
</File>
</appenders>
<loggers>
<root level="TRACE">
<appender-ref ref="Console"/>
<appender-ref ref="testFile"/>
</root>
</loggers>
</configuration>
问题描述
I'm trying to stream a basic hello world log message to show up in chainsaw from log4j2. I don't care if it uses "Zeroconf" or not, I just want something that works. I know that my test program is logging messages since they show on the console, and I know it's finding my config file because I can change the format of the messages that get printed in the console, but that's all I know.
My config file (containing various failed guesses):
<?xml version="1.0" encoding="UTF-8"?> <configuration advertiser="org.apache.logging.log4j.core.net.MulticastDNSAdvertiser"> <appenders> <Console name="Console" target="SYSTEM_OUT"> <PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %m%n"/> </Console> <File name="testFile" fileName="logs/test.log" bufferedIO="false" advertiseURI="file://localhost/home/matt/code/ade/logs/test.log" advertise="true"> <XMLLayout /> </File> <SocketAppender name="socketTest" host="localhost" immediateFlush="true" port="4560" protocol="TCP" advertiseURI="http://localhost" advertise="true"> <XMLLayout /> </SocketAppender> </appenders> <loggers> <root level="TRACE"> <appender-ref ref="Console"/> <appender-ref ref="testFile"/> <appender-ref ref="socketTest"/> </root> </loggers> </configuration>
I've tried various combinations of: including jmdns.jar on the classpath, restarting chainsaw at various points, and getting frustrated, but nothing has helped.
Any ideas?
Edit: I figured out why it couldn't read the log files I was saving to disk, (I hadn't been using XMLLayout) so I've updated the question to reflect that I now only need to get streaming working.
推荐答案
The 'advertiser' uses the log4j2 plugin mechanism, so you must provide the 'name' defined on the Advertiser in the configuration - not the fully-qualified class name.
The log4j2 advertisement mechanism currently supports advertisement of FileAppenders and SocketAppenders. However, Chainsaw only supports discovery of log4j2 FileAppenders which are advertised with a PatternLayout. XMLLayout support will show up in the near future.
The latest developer snapshot of Chainsaw must be used in order to leverage log4j2's advertiser mechanism. Chainsaw tarball and DMG available at: http://people.apache.org/~sdeboy/
Chainsaw will discover the advertised fileappender configuration and parse (and tail if you get the latest Chainsaw developer build) the log file - no Chainsaw configuration required.
Note, you need to use a PatternLayout, and JMDNS must be on the classpath of the application using this appender configuration.
Here is an example Log4j2 -appender- configuration that will advertise a fileappender configuration:
<?xml version="1.0" encoding="UTF-8"?> <configuration advertiser="multicastdns"> <appenders> <Console name="Console" target="SYSTEM_OUT"> <PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %m%n"/> </Console> <File name="testFile" fileName="logs/test.log" bufferedIO="false" advertiseURI="file:///localhost/home/matt/code/ade/logs/test.log" advertise="true"> <PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %m%n"/> </File> </appenders> <loggers> <root level="TRACE"> <appender-ref ref="Console"/> <appender-ref ref="testFile"/> </root> </loggers> </configuration>
Once you have started your app that is using the appender configuration, open the 'Zeroconf' tab in Chainsaw.
You should see a row with your appender's name (assuming you added jmdns to the classpath for the app using the fileappender configuration).
You can click 'Autoconnect' if you'd like to always start Chainsaw with this configuration if it is available.
Next, double-click on the row with the appender name and Chainsaw will start parsing and tailing your log file.
The advertised URL provided in your file appender configuration must be accessible network-wise to Chainsaw (looks like you are working locally with Chainsaw and your fileappender, so file:/// paths will work fine - note the three slashes).
Chainsaw will work best if there are delimiters around each field - square brackets, dashes, etc. as long as that character won't be present in the field you are delimiting.