开发者

How can I view log events remotely using Log4J and Apache Chainsaw?

开发者 https://www.devze.com 2022-12-20 21:43 出处:网络
I have a Java web application that currently uses Log4J for logging.I\'d like to use Apache Chainsaw to view and parse the logs remotely.So far, I\'ve had trouble understanding how to setup both the c

I have a Java web application that currently uses Log4J for logging. I'd like to use Apache Chainsaw to view and parse the logs remotely. So far, I've had trouble understanding how to setup both the client side (the Chainsaw client) and the server side (the log4j config in my webapp) to successfully enable remote logging.

Here is what I have tried so far.

Server side log4j config

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration debug="true">

   <appender name="myRFA" class="org.apache.log开发者_StackOverflow4j.RollingFileAppender">
      <param name="File" value="/logs}/my.log"/>
      <param name="Append" value="false" />
      <param name="MaxFileSize" value="10MB"/>
      <param name="MaxBackupIndex" value="10"/>
      <layout class="org.apache.log4j.PatternLayout">
         <param name="ConversionPattern"
            value="%d{ISO8601} %p - [%X{LoggingId}] - %t - %c - %m%n"/>
      </layout>
   </appender>

   <appender name="SOCKET" class="org.apache.log4j.net.SocketAppender">
      <param name="Port" value="4445"/>
      <param name="RemoteHost" value="localhost"/>
      <param name="ReconnectionDelay" value="60000"/>
      <param name="Threshold" value="DEBUG"/>
   </appender>

   <logger name="com" additivity="false">
      <level value="warn"/>
      <appender-ref ref="myRFA"/>
   </logger>

   <logger name="org" additivity="false">
      <level value="warn"/>
      <appender-ref ref="myRFA"/>
   </logger>

</log4j:configuration>

Client side Chainsaw config

I created a new receiver with the following properties

name=SOCKET
port=4445

I will admit that I don't really understand how it is all supposed to work. Is Chainsaw polling the remote server? Is the remote server connecting to Chainsaw and pushing events to it?

Guidance, links to simple tutorials, or alternate tools would all be welcome.


I think you need to add your SOCKET appender to each logger:

   <logger name="com" additivity="false">
      <level value="warn"/>
      <appender-ref ref="myRFA"/>
      <appender-ref ref="SOCKET"/>
   </logger>

   <logger name="org" additivity="false">
      <level value="warn"/>
      <appender-ref ref="myRFA"/>
      <appender-ref ref="SOCKET"/>
   </logger>
0

精彩评论

暂无评论...
验证码 换一张
取 消