0

I'd like to log apache camel route messages (HL7 format) to a specific file separate from the standard log file. How do I identify the log appender from the .to(log: route?

That is, I know in java you can call something like LoggerFactory.getLogger("hl7Logger"); and log to the specific log that way, but I can't figure how to do this in a camel route.

Here is what I have:

logback-spring.xml

<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
    <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
        <fileNamePattern>logFile.%d{yyyy-MM-dd}.log</fileNamePattern>
        <maxHistory>90</maxHistory>
    </rollingPolicy>
    <encoder>
        <charset>utf-8</charset>
        <Pattern>%d %-5level [%thread] %logger{0}: %msg%n</Pattern>
    </encoder>
</appender>

<appender name="HL7-FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
    <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
        <fileNamePattern>hl7_messages_logFile.%d{yyyy-MM-dd}.log</fileNamePattern>
        <maxHistory>90</maxHistory>
    </rollingPolicy>
    <encoder>
        <charset>utf-8</charset>
        <Pattern>%d %-5level [%thread] %logger{0}: %msg%n</Pattern>
    </encoder>
</appender>

...

<logger name="hl7Logger" level="DEBUG" additivity="false">
    <appender-ref ref="HL7-FILE"/>
</logger>

<root level="@logback.loglevel@">
    <appender-ref ref="CONSOLE"/>
    <appender-ref ref="FILE"/>
</root>

Example Route:

from("direct:complete")
        .log("Processing complete ${id}")
        .to("log:com.pavilionhealth.integration.messaging.complete?showAll=true&multiline=true&level=DEBUG&logger=hl7Logger")
        .to("hl7Complete");

I thought possibly the &logger=hl7Logger might be what is needed, but doesn't seem to log anything. Both log files are created but nothing is written to hl7_messages_logFile.2016-06-05.log only the main log file is populated

So far I've leveraged from these among others:

Logback to log different messages to two files

http://camel.apache.org/log.html

Any help at all would be much appareciated.

EDIT:

Just found a way to do it, but surely there is a more elegant solution somewhere.

I found this post , so did something like this with a custom processor.

static Logger LOG = LoggerFactory.getLogger("hl7Logger");

...

    from("direct:update")
            .process(new Processor() {
                public void process(Exchange msg) {
                    LOG.info("Processing {}", msg);
                }
            })
            .to("hl7Update");

But this isn't perfect because its not pushing the message in the nice format that .to(log: does

Community
  • 1
  • 1
wired00
  • 13,930
  • 7
  • 70
  • 73

1 Answers1

0

You can set logger name and probably add an appender which listens to that name and writes a file.

http://camel.apache.org/logeip.html

Example:

from("direct:start").log(LoggingLeven.DEBUG, org.slf4j.LoggerFactory.getLogger("com.mycompany.mylogger"), "Processing ${id}").to("bean:foo");
Souciance Eqdam Rashti
  • 3,143
  • 3
  • 15
  • 31