我目前正在使用ServiceMix在ActiveMQ队列之间路由。
<bean id="kubeActivemq" class="org.apache.activemq.camel.component.ActiveMQComponent">
<property name="brokerURL" value="tcp://172.9.9.6:30785" />
</bean>
<camelContext xmlns="http://camel.apache.org/schema/blueprint">
<route>
<from uri="kubeActivemq:queue:///SMX_CONSUMES_FROM_HERE" />
<to uri="log:EBIPMasterMessage?level=INFO&maxChars=0" />
<to uri="kubeActivemq:SMX_PRODUCES_HERE-2" />
</route>
</camelContext>
我正在使用的自定义记录器配置如下。
# Root logger
log4j.rootLogger=DEBUG, out, stdout, osgi:VmLogAppender
log4j.throwableRenderer=org.apache.log4j.OsgiThrowableRenderer
# To avoid flooding the log when using INFO level on an ssh connection and doing log:tail
log4j.logger.org.apache.sshd.server.channel.ChannelSession=INFO
# CONSOLE appender not used by default
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{ISO8601} | %-5.5p | %-16.16t | %-32.32c{1} | %X{bundle.id} - %X{bundle.name} - %X{bundle.version} | %m%n
# File appender
log4j.appender.out=org.apache.log4j.RollingFileAppender
log4j.appender.out.layout=org.apache.log4j.PatternLayout
log4j.appender.out.layout.ConversionPattern=%d{ISO8601} | %-5.5p | %-16.16t | %-32.32c{1} | %X{bundle.id} - %X{bundle.name} - %X{bundle.version} | %m%n
log4j.appender.out.file=/logs/servicemix.log
log4j.appender.out.append=true
log4j.appender.out.maxFileSize=1MB
log4j.appender.out.maxBackupIndex=10
# Sift appender
log4j.appender.sift=org.apache.log4j.sift.MDCSiftingAppender
log4j.appender.sift.key=bundle.name
log4j.appender.sift.default=servicemix
log4j.appender.sift.appender=org.apache.log4j.FileAppender
log4j.appender.sift.appender.layout=org.apache.log4j.PatternLayout
log4j.appender.sift.appender.layout.ConversionPattern=%d{ISO8601} | %-5.5p | %-16.16t | %-32.32c{1} | %m%n
log4j.appender.sift.appender.file=${karaf.data}/log/$\\{bundle.name\\}.log
log4j.appender.sift.appender.append=true
# Log EBIP Messages for Master Data queue
log4j.appender.ebipMaster=org.apache.log4j.RollingFileAppender
log4j.appender.ebipMaster.File=/logs/ebip-master.log
log4j.appender.ebipMaster.DatePattern='.'yyyy-MM-dd
log4j.appender.ebipMaster.append=true
log4j.appender.ebipMaster.layout=org.apache.log4j.PatternLayout
log4j.appender.ebipMaster.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c %3x - %m%n
log4j.appender.ebipMaster.maxFileSize=1MB
log4j.appender.ebipMaster.maxBackupIndex=10
log4j.logger.EBIPMasterMessage=DEBUG, ebipMaster
log4j.additivity.EBIPMasterMessage=false
就我的根记录器而言,我得到的日志文件样本如下:
2017-08-10 18:10:24,137 | DEBUG | SUMES_FROM_HERE] | EndpointMessageListener | 118 - org.apache.camel.camel-jms - 2.16.3 | Endpoint[kubeActivemq://SMX_CONSUMES_FROM_HERE] consumer received JMS message: ActiveMQTextMessage {commandId = 11, responseRequired = true, messageId = ID:CA00201262-61888-1502388591181-1:1:1:1:7, originalDestination = null, originalTransactionId = null, producerId = ID:CA00201262-61888-1502388591181-1:1:1:1, destination = queue://SMX_CONSUMES_FROM_HERE, transactionId = null, expiration = 0, timestamp = 1502388599084, arrival = 0, brokerInTime = 1502388624136, brokerOutTime = 1502388624136, correlationId = null, replyTo = null, persistent = true, type = null, priority = 4, groupID = null, groupSequence = 0, targetConsumerId = null, compressed = false, userID = null, content = org.apache.activemq.util.ByteSequence@4530e9b8, marshalledProperties = null, dataStructure = null, redeliveryCounter = 0, size = 0, properties = null, readOnlyProperties = true, readOnlyBody = true, droppable = false, jmsXGroupFirstForConsumer = false, text = Jun's test message 1}
2017-08-10 18:10:26,450 | DEBUG | SUMES_FROM_HERE] | JmsConfiguration | 118 - org.apache.camel.camel-jms - 2.16.3 | Sending JMS message to: queue://SMX_PRODUCES_HERE with message: ActiveMQTextMessage {commandId = 0, responseRequired = false, messageId = null, originalDestination = null, originalTransactionId = null, producerId = null, destination = null, transactionId = null, expiration = 0, timestamp = 0, arrival = 0, brokerInTime = 0, brokerOutTime = 0, correlationId = null, replyTo = null, persistent = true, type = null, priority = 4, groupID = null, groupSequence = 0, targetConsumerId = null, compressed = false, userID = null, content = null, marshalledProperties = null, dataStructure = null, redeliveryCounter = 0, size = 0, properties = {breadcrumbId=ID:CA00201262-61888-1502388591181-1:1:1:1:9, CamelJmsDeliveryMode=2}, readOnlyProperties = false, readOnlyBody = false, droppable = false, jmsXGroupFirstForConsumer = false, text = Jun's test message 1}
如您所见,日志条目输出text
字段。例如text = Jun's test message 1
有没有办法可以从日志条目中删除text
字段?
答案 0 :(得分:0)
使用自定义布局怎么样?只需展开PatternLayout并覆盖String format(LoggingEvent event)
方法。
在重写版本中,只需复制数据,然后在调用text
之前删除super.format(event)
标题。请务必不要修改传递的实际值。
然后配置自定义记录器。
# Log EBIP Messages for Master Data queue
log4j.appender.ebipMaster.layout=my.custom.DoNotPrintTextPatternLayout
由于您在ServiceMix中运行,请确保有一个暴露此类的包 请看一下这个关于类加载的问题:Fuse 6.3 dbcp basic datasource。