log4j2 to chainsaw hello world not working… what am I doing wrong?

不问归期 提交于 2019-12-02 16:57:42

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/16474939/log4j2-to-chainsaw-hello-world-not-working-what-am-i-doing-wrong

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!