log4j日志集群管理模式

Pearl ·
更新时间:2024-11-13
· 935 次阅读

服务端  服务包:log4j-1.2.17.jar,本地创建配置文件:log4j-server.properties #socket的日志 log4j.rootCategory=debug,console log4j.logger.org.apache.log4j=INFO,console #下面这个开头必须和客户端一致 log4j.logger.cn.osworks=INFO,productA log4j.logger.org.mybatis=INFO,productA log4j.logger.com.siniswift.efb=INFO,productA log4j.appender.console=org.apache.log4j.ConsoleAppender log4j.appender.console.layout=org.apache.log4j.PatternLayout log4j.appender.console.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c - %m -%l -%L -%M -%F %n #Define how the socket server should store the log events log4j.appender.file=org.apache.log4j.DailyRollingFileAppender log4j.appender.file.File=./socket.log log4j.appender.file.encoding=UTF-8 log4j.appender.file.Append=true log4j.appender.file.layout=org.apache.log4j.PatternLayout log4j.appender.file.layout.ConversionPattern=[%X{ip}][%-5p] %d{yyyy-MM-dd HH:mm:ss,SSS} [%C : %M : %L]:%m %n log4j.appender.productA=org.apache.log4j.DailyRollingFileAppender log4j.appender.productA.File=./efbmis.log log4j.appender.productA.encoding=UTF-8 log4j.appender.productA.Append=true log4j.appender.productA.layout=org.apache.log4j.PatternLayout log4j.appender.productA.layout.ConversionPattern=[%X{ip}][%-5p] %d{yyyy-MM-dd HH:mm:ss,SSS} [%C : %M : %L]:%m %n 服务启动文件:创建文件 start.bat, java -cp .\bin;.\log4j-1.2.17.jar org.apache.log4j.net.SocketServer 4560 ./log4j-server.properties ./ 客户端

配置:

log4j.rootCategory=INFO,stdout,socket #log4j.logger.com.test=DEBUG,localTestA,socket #log4j.logger.com.prodcut=DEBUG,localProductA,socket log4j.logger.cn.osworks=INFO log4j.logger.org.mybatis=INFO log4j.logger.com.siniswift.efb=INFO log4j.appender.stdout=org.apache.log4j.ConsoleAppender log4j.appender.stdout.layout=org.apache.log4j.PatternLayout log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %p [Class:%C{1}->Thread:%t] %m %n log4j.appender.socket=org.apache.log4j.net.SocketAppender log4j.appender.socket.RemoteHost=127.0.0.1 log4j.appender.socket.Port=4560 log4j.appender.socket.ReconnectionDelay=10000 log4j.appender.socket.LocationInfo=true log4j.appender.socket.layout=org.apache.log4j.PatternLayout log4j.appender.socket.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %p [Class:%C{1}->Thread:%t] %m %n 运行

1 运行服务端程序:start.bat

2 启动客户端


作者:maxiang310



集群 log4j log

需要 登录 后方可回复, 如果你还没有账号请 注册新账号