当前位置: 首页 > 工具软件 > Graylog > 使用案例 >

log4j日志接入到graylog

颜安宁
2023-12-01
logback.xml接入配置

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <property resource="graylog_config.properties"/>
    <property name="pattern" value="[%d{yyyy-MM-dd HH:mm:ss}][%-5p] [%t] [%c:%L]-%m%n%xException"/>

    <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
        <encoder>
            <pattern>${pattern}</pattern>
        </encoder>
    </appender>

    <appender name="bizSyslogAppender" class="me.moocar.logbackgelf.GelfUDPAppender">
        <remoteHost>${graylog.url}</remoteHost>
        <port>${graylog.port}</port>
        <encoder class="ch.qos.logback.core.encoder.LayoutWrappingEncoder">
            <layout class="me.moocar.logbackgelf.GelfLayout">
                <fullMessageLayout class="ch.qos.logback.classic.PatternLayout">
                    <pattern>${pattern}</pattern>
                </fullMessageLayout>
                <useLoggerName>true</useLoggerName>
                <useThreadName>true</useThreadName>
                <useMarker>true</useMarker>
                <includeFullMDC>true</includeFullMDC>
                <fieldType>requestId:long</fieldType>
                <staticField class="me.moocar.logbackgelf.Field">
                    <key>facility</key>
                    <value>SYSLOG</value>
                </staticField>
            </layout>
        </encoder>
    </appender>


    <root level="ERROR">
        <appender-ref ref="STDOUT"/>
        <appender-ref ref="bizSyslogAppender"/>
    </root>

</configuration>
 类似资料: