アクセスモード

Log Service では、次のプロダクトを使用して Log4j を収集します。
  • LogHub Log4j Appender
  • Logtail

LogHub Log4j Appender を使用した Log4j ログの収集

詳細については、「LogHub Log4j Appender」をご参照ください。

Logtail を使用した Log4j ログの収集

Log4j ログには第 1 世代および第 2 世代がありますが、本ドキュメントでは、第 1 世代のデフォルト設定を例に、Log4j の一般的な設定方法を説明します。第 2 世代の Log4j を使用している場合、完全な日付を出力するために、デフォルトの設定を修正する必要があります。
<Configuration status="WARN">
  <Appenders>
    <Console name="Console" target="SYSTEM_OUT">
      <PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss:SSS zzz} [%t] %-5level %logger{36} - %msg%n"/>
    </Console>
  </Appenders>
  <Loggers>
    <Logger name="com.foo.Bar" level="trace">
      <AppenderRef ref="Console"/>
    </Logger>
    <Root level="error">
      <AppenderRef ref="Console"/>
    </Root>
  </Loggers>
</Configuration>

Log4j のログを収集するための設定については、「Python ログ」をご参照ください。ネットワーク構成およびネットワーク設定に適した設定を選択します。

自動生成される正規表現は、ログサンプルにのみ基づいており、すべてのログフォーマットに対応しているわけではありません。したがって、正規表現が自動生成されてから、微修正する必要があります。

Log4j のログファイルに出力される Log4j のデフォルトのログフォーマットのサンプルは次のとおりです。
2013-12-25 19:57:06,954 [10.207.37.161] WARN impl.PermanentTairDaoImpl - Fail to Read Permanent Tair,key:e:470217319319741_1,result:com.example.tair.Result@172e3ebc[rc=code=-1, msg=connection error or timeout,value=,flag=0]
複数行ログの行の先頭を一致させる (IP アドレスで行の先頭を示す)
\d+-\d+-\d+\s.
ログデータの抽出に使用される正規表現
(\d+-\d+-\d+\s\d+:\d+:\d+,\d+)\s\[([^\]]*)\]\s(\S+)\s+(\S+)\s-\s(.
時間の変換書式
%Y-%m-%d %H:%M:%S
ログサンプルの抽出結果
キー
time 2013-12-25 19:57:06,954
ip 10.207.37.161
level WARN
class impl.PermanentTairDaoImpl
message Fail to Read Permanent Tair,key:e:470217319319741_1,result:com.example.tair.Result@172e3ebc[rc=code=-1, msg=connection error or timeout,value=,flag=0]