Discussion:
Problem writing camel logs with log4j in a spring-boot application
Ranabroto Ghosh
2018-08-06 12:33:31 UTC
Permalink
Hi
I have a Spring-boot application with Apache Camel. All I am trying to
achieve here writing all logs(java log and also camel route level logs
using camel 'log' EIP) in a log file using log4j.



*My POM: *

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
</exclusions>
</dependency>

<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-spring-boot</artifactId>
<version>${camel.version}</version>
</dependency>

<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.16</version>
</dependency>


*LOG4J properties file: *
log4j.rootLogger=info, rollinglog, rollingerrorlog

log4j.logger.org.apache.camel=INFO

# File output configuration
log4j.appender.rollinglog=org.apache.log4j.DailyRollingFileAppender
log4j.appender.rollinglog.File=C://logs/testgateway.log
log4j.appender.rollinglog.Threshold=INFO

# roll over the file at the end of each day and append the date to the end
of the file
log4j.appender.rollinglog.DatePattern='.'yyyy-MM-dd

# Configure the layout for the log file
log4j.appender.rollinglog.layout=org.apache.log4j.PatternLayout
log4j.appender.rollinglog.layout.ConversionPattern=(%d) %p %t %c - %m%n

# File output configuration
log4j.appender.rollingerrorlog=org.apache.log4j.DailyRollingFileAppender
log4j.appender.rollingerrorlog.File=C://logs/ testgateway.log
log4j.appender.rollingerrorlog.Threshold=ERROR

# roll over the file at the end of each day and append the date to the end
of the file
log4j.appender.rollingerrorlog.DatePattern='.'yyyy-MM-dd

# Configure the layout for the log file
log4j.appender.rollingerrorlog.layout=org.apache.log4j.PatternLayout
log4j.appender.rollingerrorlog.layout.ConversionPattern=(%d) %p %t %c - %m%n


*My Camel route: *

<route id="test-route" autoStartup="true">
<from uri="restlet:/test"/>

<!-- Logs are getting printed correctly in expected log file from below
java method-->
<to uri="bean:sendMessage?method=test"/>

<!-- Logs are not getting printed in expected log file from below log EIP-->

<log message="HEADER: ${headers}"/>
</route>

So I am confused why camel log not getting printed from camel contexts
wjere java logs are working fine, could you please guide me what I am
missing here
--
Kind Regards
Rana
Claus Ibsen
2018-08-06 13:37:27 UTC
Permalink
Hi

Its probably more of a Spring Boot question how to configure its logging.
I suggest to study their documentation.

Camel uses the slf4j-api and that ought to work fine with SB.

On Mon, Aug 6, 2018 at 2:33 PM, Ranabroto Ghosh
Post by Ranabroto Ghosh
Hi
I have a Spring-boot application with Apache Camel. All I am trying to
achieve here writing all logs(java log and also camel route level logs
using camel 'log' EIP) in a log file using log4j.
*My POM: *
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-spring-boot</artifactId>
<version>${camel.version}</version>
</dependency>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.16</version>
</dependency>
*LOG4J properties file: *
log4j.rootLogger=info, rollinglog, rollingerrorlog
log4j.logger.org.apache.camel=INFO
# File output configuration
log4j.appender.rollinglog=org.apache.log4j.DailyRollingFileAppender
log4j.appender.rollinglog.File=C://logs/testgateway.log
log4j.appender.rollinglog.Threshold=INFO
# roll over the file at the end of each day and append the date to the end
of the file
log4j.appender.rollinglog.DatePattern='.'yyyy-MM-dd
# Configure the layout for the log file
log4j.appender.rollinglog.layout=org.apache.log4j.PatternLayout
log4j.appender.rollinglog.layout.ConversionPattern=(%d) %p %t %c - %m%n
# File output configuration
log4j.appender.rollingerrorlog=org.apache.log4j.DailyRollingFileAppender
log4j.appender.rollingerrorlog.File=C://logs/ testgateway.log
log4j.appender.rollingerrorlog.Threshold=ERROR
# roll over the file at the end of each day and append the date to the end
of the file
log4j.appender.rollingerrorlog.DatePattern='.'yyyy-MM-dd
# Configure the layout for the log file
log4j.appender.rollingerrorlog.layout=org.apache.log4j.PatternLayout
log4j.appender.rollingerrorlog.layout.ConversionPattern=(%d) %p %t %c - %m%n
*My Camel route: *
<route id="test-route" autoStartup="true">
<from uri="restlet:/test"/>
<!-- Logs are getting printed correctly in expected log file from below
java method-->
<to uri="bean:sendMessage?method=test"/>
<!-- Logs are not getting printed in expected log file from below log EIP-->
<log message="HEADER: ${headers}"/>
</route>
So I am confused why camel log not getting printed from camel contexts
wjere java logs are working fine, could you please guide me what I am
missing here
--
Kind Regards
Rana
--
Claus Ibsen
-----------------
http://davsclaus.com @davsclaus
Camel in Action 2: https://www.manning.com/ibsen2
RavinderReddy k
2018-08-06 13:40:25 UTC
Permalink
Simple solution is use logback.xml file include in your spring boot
application that's all.
Post by Claus Ibsen
Hi
Its probably more of a Spring Boot question how to configure its logging.
I suggest to study their documentation.
Camel uses the slf4j-api and that ought to work fine with SB.
On Mon, Aug 6, 2018 at 2:33 PM, Ranabroto Ghosh
Post by Ranabroto Ghosh
Hi
I have a Spring-boot application with Apache Camel. All I am trying to
achieve here writing all logs(java log and also camel route level logs
using camel 'log' EIP) in a log file using log4j.
*My POM: *
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-spring-boot</artifactId>
<version>${camel.version}</version>
</dependency>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.16</version>
</dependency>
*LOG4J properties file: *
log4j.rootLogger=info, rollinglog, rollingerrorlog
log4j.logger.org.apache.camel=INFO
# File output configuration
log4j.appender.rollinglog=org.apache.log4j.DailyRollingFileAppender
log4j.appender.rollinglog.File=C://logs/testgateway.log
log4j.appender.rollinglog.Threshold=INFO
# roll over the file at the end of each day and append the date to the
end
Post by Ranabroto Ghosh
of the file
log4j.appender.rollinglog.DatePattern='.'yyyy-MM-dd
# Configure the layout for the log file
log4j.appender.rollinglog.layout=org.apache.log4j.PatternLayout
log4j.appender.rollinglog.layout.ConversionPattern=(%d) %p %t %c - %m%n
# File output configuration
log4j.appender.rollingerrorlog=org.apache.log4j.DailyRollingFileAppender
log4j.appender.rollingerrorlog.File=C://logs/ testgateway.log
log4j.appender.rollingerrorlog.Threshold=ERROR
# roll over the file at the end of each day and append the date to the
end
Post by Ranabroto Ghosh
of the file
log4j.appender.rollingerrorlog.DatePattern='.'yyyy-MM-dd
# Configure the layout for the log file
log4j.appender.rollingerrorlog.layout=org.apache.log4j.PatternLayout
log4j.appender.rollingerrorlog.layout.ConversionPattern=(%d) %p %t %c -
%m%n
Post by Ranabroto Ghosh
*My Camel route: *
<route id="test-route" autoStartup="true">
<from uri="restlet:/test"/>
<!-- Logs are getting printed correctly in expected log file from below
java method-->
<to uri="bean:sendMessage?method=test"/>
<!-- Logs are not getting printed in expected log file from below log
EIP-->
Post by Ranabroto Ghosh
<log message="HEADER: ${headers}"/>
</route>
So I am confused why camel log not getting printed from camel contexts
wjere java logs are working fine, could you please guide me what I am
missing here
--
Kind Regards
Rana
--
Claus Ibsen
-----------------
Camel in Action 2: https://www.manning.com/ibsen2
Claus Ibsen
2018-08-06 13:41:14 UTC
Permalink
Post by RavinderReddy k
Simple solution is use logback.xml file include in your spring boot
application that's all.
Yeah SB uses logback as the logger impl by default.
Post by RavinderReddy k
Post by Claus Ibsen
Hi
Its probably more of a Spring Boot question how to configure its logging.
I suggest to study their documentation.
Camel uses the slf4j-api and that ought to work fine with SB.
On Mon, Aug 6, 2018 at 2:33 PM, Ranabroto Ghosh
Post by Ranabroto Ghosh
Hi
I have a Spring-boot application with Apache Camel. All I am trying to
achieve here writing all logs(java log and also camel route level logs
using camel 'log' EIP) in a log file using log4j.
*My POM: *
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-spring-boot</artifactId>
<version>${camel.version}</version>
</dependency>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.16</version>
</dependency>
*LOG4J properties file: *
log4j.rootLogger=info, rollinglog, rollingerrorlog
log4j.logger.org.apache.camel=INFO
# File output configuration
log4j.appender.rollinglog=org.apache.log4j.DailyRollingFileAppender
log4j.appender.rollinglog.File=C://logs/testgateway.log
log4j.appender.rollinglog.Threshold=INFO
# roll over the file at the end of each day and append the date to the
end
Post by Ranabroto Ghosh
of the file
log4j.appender.rollinglog.DatePattern='.'yyyy-MM-dd
# Configure the layout for the log file
log4j.appender.rollinglog.layout=org.apache.log4j.PatternLayout
log4j.appender.rollinglog.layout.ConversionPattern=(%d) %p %t %c - %m%n
# File output configuration
log4j.appender.rollingerrorlog=org.apache.log4j.DailyRollingFileAppender
log4j.appender.rollingerrorlog.File=C://logs/ testgateway.log
log4j.appender.rollingerrorlog.Threshold=ERROR
# roll over the file at the end of each day and append the date to the
end
Post by Ranabroto Ghosh
of the file
log4j.appender.rollingerrorlog.DatePattern='.'yyyy-MM-dd
# Configure the layout for the log file
log4j.appender.rollingerrorlog.layout=org.apache.log4j.PatternLayout
log4j.appender.rollingerrorlog.layout.ConversionPattern=(%d) %p %t %c -
%m%n
Post by Ranabroto Ghosh
*My Camel route: *
<route id="test-route" autoStartup="true">
<from uri="restlet:/test"/>
<!-- Logs are getting printed correctly in expected log file from below
java method-->
<to uri="bean:sendMessage?method=test"/>
<!-- Logs are not getting printed in expected log file from below log
EIP-->
Post by Ranabroto Ghosh
<log message="HEADER: ${headers}"/>
</route>
So I am confused why camel log not getting printed from camel contexts
wjere java logs are working fine, could you please guide me what I am
missing here
--
Kind Regards
Rana
--
Claus Ibsen
-----------------
Camel in Action 2: https://www.manning.com/ibsen2
--
Claus Ibsen
-----------------
http://davsclaus.com @davsclaus
Camel in Action 2: https://www.manning.com/ibsen2
Loading...