Linux服务器配置
编辑/etc/rsyslog.conf文件。(我的在这里,根据自己系统查看)
# 取消注释这几行
$ModLoad imudp
$UDPServerRun 514
# Provides TCP syslog reception
$ModLoad imtcp
$InputTCPServerRun 514
..........
# 末位追加:
local2.info /var/log/login_info.log
local2.debug /var/log/login_debug.log
重启rsyslog服务
systemctl restart rsyslog.service
引用:https://blog.csdn.net/yuge_legend/article/details/118731653
下面两种选其一即可
Log4j
- 添加依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-log4j</artifactId>
<version>1.3.8.RELEASE</version>
</dependency>
- 配置文件
resource下增加log4j.properties文件
log4j.rootLogger=debug,Console,SYSLOG,File
log4j.appender.Console=org.apache.log4j.ConsoleAppender
log4j.appender.Console.Target=System.out
log4j.appender.Console.layout = org.apache.log4j.PatternLayout
log4j.appender.Console.layout.ConversionPattern=[%p] [%d{yyyy-MM-dd HH\:mm\:ss}][%c - %L]%m%n
log4j.appender.File = org.apache.log4j.RollingFileAppender
#本地日志存储路径
log4j.appender.File.File = D:\\info.log
log4j.appender.File.MaxFileSize = 10MB
log4j.appender.File.Threshold = ALL
log4j.appender.File.layout = org.apache.log4j.PatternLayout
log4j.appender.File.layout.ConversionPattern =[%p] [%d{yyyy-MM-dd HH\:mm\:ss}][%c - %L]%m%n
log4j.appender.SYSLOG=org.apache.log4j.net.SyslogAppender
#远程syslog服务器,无法设置端口
log4j.appender.SYSLOG.syslogHost=192.168.88.134
log4j.appender.syslog.Threshold=ALL
log4j.appender.SYSLOG.layout=org.apache.log4j.PatternLayout
log4j.appender.SYSLOG.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n
log4j.appender.SYSLOG.Header=true
log4j.appender.SYSLOG.Facility=local2
Logback
- 配置logback-spring.xml中appender标签. 一般在resources目录下创建该文件。
- 增加配置:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<appender name="SYSLOG" class="ch.qos.logback.classic.net.SyslogAppender">
<syslogHost>目标ip地址</syslogHost>
<port>514</port>
<facility>LOCAL1</facility>
<suffixPattern>%d{yyyy-MM-dd HH:mm:ss.SSS}|${appName}|${env}|%-5level|%thread|%C:%M:%L| - %msg</suffixPattern>
</appender>
<root level="info">
<appender-ref ref="SYSLOG"/>
</root>
</configuration>
引用:https://blog.csdn.net/x41990/article/details/126521171
标签:layout,springboot,SYSLOG,log4j,syslog,File,org,logback,appender From: https://www.cnblogs.com/xxsdnol/p/17913948.html