直接用logback将控制台输出的日志发送到graylog上
1.导入logback依赖
<dependency>
<groupId>de.siegmar</groupId>
<artifactId>logback-gelf</artifactId>
<version>1.1.0</version>
</dependency>
2.创建logback-spring.xml配置文件
<configuration debug="true"><appender name="GELF" class="de.siegmar.logbackgelf.GelfTcpAppender">
<graylogHost>192.168.000.000</graylogHost>
<graylogPort>12201</graylogPort>
</appender><!-- Use AsyncAppender to prevent slowdowns -->
<appender name="ASYNC GELF" class="ch.qos.logback.classic.AsyncAppender">
<appender-ref ref="GELF" />
<neverBlock>true</neverBlock>
</appender><root level="info">
<appender-ref ref="ASYNC GELF" />
</root></configuration>
- GELF配置的是你graylog提供的外网ip,以及配置的input端口
- ASYNC GELF就是异步来执行GELF减少对项目资源的消耗
- root里level就是发送什么级别的日志
3.Graylog配置input
然后保存即可,在graylog的search界面就能收到日志了