lilith 를 사용하여 logback 으로 기록한 log message 를 Network 으로 전달 및 취합

Lilith 는 logback 의 로그 메시지를 네트웍으로 전달하고 전용 viewer 를 통해 event 나 level 등으로 구분하여 볼 수 있는 유틸리티이다. Chainsaw 와 비슷한 역할을 하며 차이점은 Lilith 는 더 고성능이며 대용량의 log 파일을 다룰수 있다고 한다.

개인적으로 로깅 시스템은 slf4j 를 기반으로 하여 logback 만 사용하므로 logback 에서 사용 방법만 정리해 본다.

설정

logback-classic SocketAppender 와 사용

Lilith 는 logback-classic의 SocketAppender 를 위해 4560 port 를 리슨하고 있다. 다음 내용을 logback.xml 에 추가하면 된다.

<appender name="LogbackClassic" class="ch.qos.logback.classic.net.SocketAppender">
    <RemoteHost>localhost</RemoteHost>
    <Port>4560</Port>
    <ReconnectionDelay>170</ReconnectionDelay>
    <IncludeCallerData>true</IncludeCallerData>
</appender>

logger 에 적당한 appender 를 지정해 주거나(Ex: root logger)

<root level="INFO">
    <appender-ref ref="LogbackClassic"/>
</root>

logger 를 지정해 줄 수 있다.

<logger name="foo.Bar" level="DEBUG">
    <appender-ref ref="LogbackClassic"/>
</logger>

 

Lilith ClassicMultiplexSocketAppender

Lilith is listening for Lilith ClassicMultiplexSocketAppender connections on port 10000 (compressed) and 10001 (uncompressed).

The Lilith ClassicMultiplexSocketAppender is a replacement for the logback-classic SocketAppender.

This appender, in contrast to logbacks, supports logger.debug("{} {}", new Object[]{foo, bar, throwable), i.e. if the last given parameter of a log message is a Throwable and it is not used up in the message pattern then it will be used as the Throwable of the LoggingEvent, similar to logger.debug(""+foo+" "+bar, throwable).

 

This has several benefits:

  • Sending to multiple remote hosts is supported while the event is only serialized once.
  • Events can (and should) be compressed using GZIP.
  • The appender supports heartbeat and timeout.
    • The event receiver can find out that the event sender connection died if a heartbeat is missing.
    • The event sender can find out that the event receiver connection died by means of a timeout This means that an application won't stop (at least not for very long) in case of network problem.

 

Add the following to your applications logback.xml:

logback.xml
<appender name="multiplex" class="de.huxhorn.lilith.logback.appender.ClassicMultiplexSocketAppender">
    <Compressing>true</Compressing>
    <!-- will automatically use correct default port -->
    <!-- Default port for compressed is 10000 and uncompressed 10001 -->
    <ReconnectionDelay>10000</ReconnectionDelay>
    <IncludeCallerData>true</IncludeCallerData>
    <RemoteHosts>localhost, 10.200.55.13</RemoteHosts>
    <!-- Alternatively:
    <RemoteHost>localhost</RemoteHost>
    <RemoteHost>10.200.55.13</RemoteHost>
    -->
    <!--
    Optional:
    <CreatingUUID>false</CreatingUUID>
    -->
</appender>

You also have to attach the appender to some logger, e.g. the root logger...

<root level="INFO">
    <appender-ref ref="multiplex"/>
</root>

... or a specific logger...

<logger name="foo.Bar" level="DEBUG">
    <appender-ref ref="multiplex"/>
</logger>

Using Lilith ClassicMultiplexSocketAppender requiresde.huxhorn.lilith:de.huxhorn.lilith.logback.appender.multiplex-classic as runtime dependency.

pom.xml
<dependency>
	<groupId>de.huxhorn.lilith</groupId>
	<artifactId>de.huxhorn.lilith.logback.appender.multiplex-classic</artifactId>
	<version>${lilithVersion}</version>
	<scope>runtime</scope>
</dependency>


See Also

 

Ref