我正在使用
域模式下的jboss
并将其配置为为所有托管服务器创建合并日志文件
现在,我希望日志消息中的服务器名称是我可以尝试使用简单Java的任何方法。
I expect these results
11:44:01,937信息[标准输出](schedulerFactoryBean_Worker-1)MyTaskOne启动。。
11:44:01,938信息[stdout](schedulerFactoryBean_Worker-1)作业在服务器一上运行
11:44:01,937信息[标准输出](schedulerFactoryBean_Worker-1)MyTaskOne启动。。
11:44:01,938信息[stdout](schedulerFactoryBean_Worker-1)作业在第二台服务器上运行
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE log4j:configuration SYSTEM "log4j.dtd"> <log4j:configuration debug="false" xmlns:log4j='http://jakarta.apache.org/log4j/'> <appender name="stdout" class="org.apache.log4j.ConsoleAppender"> <layout class="org.apache.log4j.PatternLayout" > <param name="ConversionPattern" value="[%c] (%x:%t) [User:%X{logguserid}] %m%n"/> </layout> </appender> <appender name="AppLogWriter" class="org.apache.log4j.RollingFileAppender"> <param name="File" value="D:/jboss-as-7.1.1.Final/domain/log/server.log"/> <param name="Append" value="true"/> <param name="MaxFileSize" value="10MB"/> <param name="MaxBackupIndex" value="100"/> <layout class="org.apache.log4j.PatternLayout"> <param name="ConversionPattern" value="%d %-5r %-5p [%c] (%x:%t) [User:%X{logguserid}] %m%n"/> </layout> </appender> <appender name="AuditLogWriter" class="org.apache.log4j.RollingFileAppender"> <param name="File" value="D:/jboss-as-7.1.1.Final/domain/log/server.log"/><!--path of auditlog file--> <param name="Append" value="true"/> <param name="MaxFileSize" value="10MB"/> <param name="MaxBackupIndex" value="10"/> <layout class="org.apache.log4j.PatternLayout"> <param name="ConversionPattern" value="%d %-5r %-5p [%c] (%x:%t) [User:%X{logguserid}] %m%n"/> </layout> </appender> <root> <priority value="info"/> <appender-ref ref="AppLogWriter"/> <appender-ref ref="stdout"/> </root> <logger name=".audit.log" level="info" additivity="false"> <appender-ref ref="AuditLogWriter" /> </logger> <appender name="CLASSLOADING" class="org.apache.log4j.RollingFileAppender"> <errorHandler class="org.jboss.logging.util.OnlyOnceErrorHandler"/> <param name="File" value= "D:/Logs/classloading.log"/> <param name="Append" value="false"/> <param name="MaxFileSize" value="5000KB"/> <param name="MaxBackupIndex" value="10"/> <layout class="org.apache.log4j.PatternLayout"> <param name="ConversionPattern" value="%d %m%n"/> </layout> </appender> <category name="org.jboss.classloading"> <priority value="TRACE"/> <appender-ref ref="CLASSLOADING"/> </category> </log4j:configuration>
11:44:01,427 INFO [com.Quartz_Oracle_11g.task.MyTaskOne] (schedulerFactoryBean_Worker-1) this is a info message
11:44:01,428 WARN [com.Quartz_Oracle_11g.task.MyTaskOne] (schedulerFactoryBean_Worker-1) this is a warn message
11:44:01,429 ERROR [com.Quartz_Oracle_11g.task.MyTaskOne] (schedulerFactoryBean_Worker-1) this is a error message
11:44:01,431 INFO [stdout] (schedulerFactoryBean_Worker-1) MyTaskOne done..
11:44:01,728 INFO [org.springframework.batch.core.job.SimpleStepHandler] (schedulerFactoryBean_Worker-1) Duplicate step [stepOne] detected in execution of job=[demoJob]. If either step fails, both will be executed again on restart.
11:44:01,862 INFO [org.springframework.batch.core.job.SimpleStepHandler] (schedulerFactoryBean_Worker-1) Executing step: [stepOne]
11:44:01,937 INFO [stdout] (schedulerFactoryBean_Worker-1) MyTaskOne start..
11:44:01,938 INFO [stdout] (schedulerFactoryBean_Worker-1) Job
11:44:01,938 INFO [com.Quartz_Oracle_11g.task.MyTaskOne] (schedulerFactoryBean_Worker-1) this is a info message
11:44:01,939 WARN [com.Quartz_Oracle_11g.task.MyTaskOne] (schedulerFactoryBean_Worker-1) this is a warn message
11:44:01,940 ERROR [com.Quartz_Oracle_11g.task.MyTaskOne] (schedulerFactoryBean_Worker-1) this is a error message
11:44:01,941 INFO [stdout] (schedulerFactoryBean_Worker-1) MyTaskOne done..
11:44:02,151 INFO [org.springframework.batch.core.launch.support.SimpleJobLauncher] (schedulerFactoryBean_Worker-1) Job: [SimpleJob: [name=demoJob]] completed with the following parameters: [{JobID=1573539240754}] and the following status: [COMPLETED]
11:44:02,153 INFO [org.quartz.plugins.history.LoggingTriggerHistoryPlugin] (schedulerFactoryBean_Worker-1) Trigger [DEFAULT.jobTrigger] completed firing job [DEFAULT.demoJob] with resulting trigger instruction code: DO NOTHING. Next scheduled at: 12-11-2019 11:45:00.000
MDC.put("jboss.server.name", System.getProperty("jboss.server.name"));
比您可以将其添加到Log4j转换模式:
"... [jboss-server-name=%X{jboss.server.name}] ..."