我有2个具有不同包装结构的单独的可展开式耳罩,如下所示。两者都是逻辑上分离的工件。两者在log4j2.xml中使用不同的异步附加程序分隔了不同的不同日志文件
Ear 1: com.org.module1.<classes>
log file name is module1.log
Ear 2: com.org.module2.<classes>
log file name is module2.log
log4j2.xml详细信息和log4
<AsyncLogger name="com.org.module1" level="DEBUG" additivity="false">
<AppenderRef ref="STDOUT"/>
<AppenderRef ref="STDERR" level="ERROR"/>
<AppenderRef ref="Module1_File"/>
</AsyncLogger>
<RollingRandomAccessFile name="Module1_File" fileName="${logLocation}/Module1_File.log" filePattern="${logLocation}/Module1_File-%d{MM-dd-yyyy}-%i.log" immediateFlush="false">
<PatternLayout pattern="%d %-5level [%t] - %msg%n"/>
<Policies>
<TimeBasedTriggeringPolicy />
<SizeBasedTriggeringPolicy size="50MB"/>
</Policies>
<DefaultRolloverStrategy max="20"/>
</RollingRandomAccessFile>
<AsyncLogger name="com.org.module2" level="DEBUG" additivity="false">
<AppenderRef ref="STDOUT"/>
<AppenderRef ref="STDERR" level="ERROR"/>
<AppenderRef ref="Module2_File"/>
</AsyncLogger>
<RollingRandomAccessFile name="Module2_File" fileName="${logLocation}/Module2_File.log" filePattern="${logLocation}/Module2_File-%d{MM-dd-yyyy}-%i.log" immediateFlush="false">
<PatternLayout pattern="%d %-5level [%t] - %msg%n"/>
<Policies>
<TimeBasedTriggeringPolicy />
<SizeBasedTriggeringPolicy size="50 MB"/>
</Policies>
<DefaultRolloverStrategy max="20"/>
</RollingRandomAccessFile>
和log4j.properties
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.Mail.layout.ConversionPattern=%d %-5p %c - %m%n
log4j.appender.mail.From=app-errors@yourdomain.com
log4j.appender.Custom=com.org.module1.logger.log4j.CustomFileAppender
log4j.appender.Custom.layout=com.org.module1.logger.log4j.SimpleLayout
log4j.appender.stdout.layout.ConversionPattern=%d %5p [%t] [%X{_defCtx}] - %m%n
log4j.appender.mail=org.apache.log4j.net.SMTPAppender
log4j.logger.CustomLogger=info,Custom
log4j.appender.Custom.Directory=messages
log4j.appender.mail.BufferSize=1
log4j.additivity.CustomLogger=false
log4j.appender.R.layout.ConversionPattern=%d %5p [%t] [%X{_defCtx}] - %m%n
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.R.File=platform.log
log4j.appender.mail.To=app-errors@yourdomain.com
log4j.appender.R.MaxBackupIndex=5
log4j.appender.Mail.layout=org.apache.log4j.PatternLayout
log4j.appender.R=org.apache.log4j.RollingFileAppender
log4j.appender.mail.Threshold=ERROR
log4j.appender.R.layout=org.apache.log4j.PatternLayout
log4j.appender.R.MaxFileSize=1000KB
log4j.appender.mail.Subject=Application Error
log4j.logger.com.org=debug, stdout,R
log4j.rootLogger=error, stdout,R
log4j.appender.mail.SMTPHost=mail.yourdomain.com
log4j.appender.Custom.maxBackupIndex=600
但是,两个日志都使用了一个jar,该jar是耳下包装,并且具有不同的包装结构,例如“ com.org.shared.util”。
当前,我为共享jar创建了一个Appender,其日志将如下记录。
<AsyncLogger name="com.org.shared.util" level="DEBUG" additivity="false">
<AppenderRef ref="STDOUT"/>
<AppenderRef ref="STDERR" level="ERROR"/>
<AppenderRef ref="Shared_File"/>
</AsyncLogger>
<RollingRandomAccessFile name="Shared_File" fileName="${logLocation}/Shared_File.log" filePattern="${logLocation}/Shared_File-%d{MM-dd-yyyy}-%i.log" immediateFlush="false">
<PatternLayout pattern="%d %-5level [%t] - %msg%n"/>
<Policies>
<TimeBasedTriggeringPolicy />
<SizeBasedTriggeringPolicy size="50MB"/>
</Policies>
<DefaultRolloverStrategy max="20"/>
</RollingRandomAccessFile>
问题是
我如何确保何时从module1耳朵调用共享jar类时应登录到Module1_File.log,而不是其自己的Shared_File.log。由于此处的包表达式不同,并且类似地在从module2调用时,包耳应记录到Module2_File.log中。
有没有一种方法可以在应用程序流程期间合并附加程序/路由module1 + Shared_file的附加程序。什么是替代解决方案?
类似于Module2吗?请提出宝贵意见。