简体   繁体   English

mule用流量定制记录器

[英]mule customizing the logger with flows

I have four flows each is having http end point: 我有四个流程,每个流程都有http终点:

<flow1 >
<http:myhosts:port path="test1">
</flow1>
<flow2>
<http:myhosts:port path="test2">
</flow2>
<flow3>
<http:myhosts:port path="test3">
</flow3>
<flow4>
<http:myhosts:port path="test4">
</flow1>

I am using mule 3.5, have defined log4j.properties as 我使用的是mule 3.5,已将log4j.properties定义为

log = /tmp
log4j.rootLogger=INFO, file
log4j.appender.file=org.apache.log4j.DailyRollingFileAppender
log4j.appender.file.File=${log}/mylogs.log
log4j.appender.file.DatePattern='.'ddMMyyyy
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
log4j.appender.console=org.apache.log4j.ConsoleAppender    
log4j.appender.console.Threshold=ERROR
log4j.appender.console.layout=org.apache.log4j.PatternLayout
log4j.appender.console.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n

It prints logger in tmp directory with a single file name. 它使用单个文件名在tmp目录中打印记录器。

What I need to make is, for each flow or url, mule have to create logfiles as test1-12:20:00(present-time).log So If I run 4 flows, then I need to have 4 logger files should be created as 我需要做的是,对于每个流或网址,骡子必须创建日志文件作为test1-12:20:00(当前时间).log所以如果我运行4个流程,那么我需要有4个记录器文件应该是创建为

test1-12:20:00(present-time).log
test1-13:20:00(present-time).log
test1-14:20:00(present-time).log
test1-15:20:00(present-time).log

How do I make this? 我该怎么做? Is this possible to do in Mule configuration? 这可以在Mule配置中做到吗?

You won't be able to do that in just with log4j without a lot of work. 如果没有大量的工作,你将无法使用log4j。 However you could prepend your logger messages with #[flow.name] . 但是,您可以使用#[flow.name]记录器消息。

I think you could accomplish this using categories. 我认为你可以使用类别完成此任务。

First, create four separate appenders in log4j. 首先,在log4j中创建四个单独的appender。 For Mule 3.5, you may continue using the properties configuration but keep in mind you will have to go to XML configuration in Mule 3.6 because of the move to log4j2. 对于Mule 3.5,您可以继续使用属性配置,但请记住,由于迁移到log4j2,您必须转到Mule 3.6中的XML配置。

log4j.appender.thing1=org.apache.log4j.DailyRollingFileAppender
log4j.appender.thing1.File=/var/log/integration/Thing1/mylogs.log
# etc...
log4j.appender.thing2=org.apache.log4j.DailyRollingFileAppender
log4j.appender.thing2.File=/var/log/integration/Thing2/mylogs.log
# etc...

Then, define loggers for specific categories like so: 然后,为特定类别定义记录器,如下所示:

log4j.logger.com.mycompany.Thing1=DEBUG,thing1
log4j.logger.com.mycompany.Thing2=DEBUG,thing2
# etc...

Finally, add loggers in your flows that use the appropriate category: 最后,在使用适当类别的流中添加记录器:

<flow name="Thing1">
    <!-- your flow logic goes here -->
    <logger category="com.mycompany.Thing1" message="Something happened" level="INFO" />
    <!-- more flow logic goes here -->
</flow>

<flow name="Thing2">
    <!-- your other flow logic goes here -->
    <logger category="com.mycompany.Thing2" message="Something happened in flow 2" level="INFO" />
    <!-- more flow logic goes here -->
</flow>

Note that when you move to 3.6 and begin using log4j2, you will be able to take advantage of the more flexible RollingFileAppender and have greater control over when rolling happens and how the file names are generated. 请注意,当您移至3.6并开始使用log4j2时,您将能够利用更灵活的RollingFileAppender ,并更好地控制何时进行滚动以及如何生成文件名。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM