log4j2到电锯你好世界无法正常工作...我在做什么错? [英] log4j2 to chainsaw hello world not working... what am I doing wrong?

查看:121
本文介绍了log4j2到电锯你好世界无法正常工作...我在做什么错?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试流式传输基本的hello world日志消息,以显示在log4j2的电锯中.我不在乎它是否使用"Zeroconf",我只是想要一些有效的方法.我知道我的测试程序正在记录消息,因为它们显示在控制台上,而且我知道它正在查找我的配置文件,因为我可以更改在控制台上打印的消息的格式,但这就是我所知道的.

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>

我尝试了以下各种组合:在类路径上包括jmdns.jar,在各个点重新启动电锯,并感到沮丧,但没有任何帮助.

I've tried various combinations of: including jmdns.jar on the classpath, restarting chainsaw at various points, and getting frustrated, but nothing has helped.

有什么想法吗?

我弄清楚了为什么它无法读取我保存到磁盘的日志文件,(我没有使用XMLLayout),所以我更新了问题以反映现在我只需要使流工作即可

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.

推荐答案

"advertiser"使用log4j2插件机制,因此您必须在配置中提供在Advertiser上定义的名称",而不是完全限定的类名.

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.

log4j2公告机制当前支持FileAppenders和SocketAppenders的公告.但是,电锯仅支持发现使用PatternLayout通告的log4j2 FileAppender. XMLLayout支持将在不久的将来出现.

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.

必须使用Chainsaw的最新开发人员快照,才能利用log4j2的广告商机制.可在以下位置找到电锯tarball和DMG: http://people.apache.org/~sdeboy/

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将发现广告文件的appender配置,并解析日志文件(如果获得最新的Chainsaw开发人员版本,则会解析该日志文件)-无需Chainsaw配置.

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.

请注意,您需要使用PatternLayout,并且使用此附加程序配置,JMDNS必须位于应用程序的类路径上.

Note, you need to use a PatternLayout, and JMDNS must be on the classpath of the application using this appender configuration.

下面是一个示例Log4j2 -appender-配置,它将发布文件appender配置:

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>

启动使用附加程序的应用程序后 配置,请打开电锯中的"Zeroconf"标签.

Once you have started your app that is using the appender configuration, open the 'Zeroconf' tab in Chainsaw.

您应该看到一行带有您的追加者姓名的行(假设您添加了 jmdns到使用fileappender的应用程序的类路径 配置).

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.

下一步,双击 在带有附加程序名称的行上,Chainsaw将开始解析和尾随日志文件.

Next, double-click on the row with the appender name and Chainsaw will start parsing and tailing your log file.

文件附加器中提供的广告URL 配置必须可以通过链锯从网络进行访问(看起来您正在工作) 使用Chainsaw和您的fileappender在本地进行操作,因此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.

这篇关于log4j2到电锯你好世界无法正常工作...我在做什么错?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆