Camel log4j configuration when deployed inside ActiveMQ - java

I'm running some Camel 2.12.2 routes deployed inside ActiveMQ 5.9.0.
The ActiveMQ log4j is working as expected, but I'm not able to get a log for my camel application when deployed inside ActiveMQ. My Camel log4j.properties looks like this:
#
# The logging properties used
#
log4j.rootLogger=INFO, console, logger
# uncomment the following line to turn on Camel debugging
#log4j.logger.org.apache.camel=DEBUG
# Console appender
log4j.appender.console=org.apache.log4j.ConsoleAppender
log4j.appender.console.layout=org.apache.log4j.PatternLayout
log4j.appender.console.layout.ConversionPattern=%5p | %m%n
log4j.appender.console.threshold=INFO
# File appender
log4j.appender.logger=org.apache.log4j.RollingFileAppender
log4j.appender.logger.file=camel.log
log4j.appender.logger.maxFileSize=1024KB
log4j.appender.logger.maxBackupIndex=5
log4j.appender.logger.append=true
log4j.appender.logger.layout=org.apache.log4j.PatternLayout
log4j.appender.logger.layout.ConversionPattern=%d | %-5p | %m | %c | %t%n
My camel project is using JavaDSL with SpringRouteBuilders, and when running the application with the maven camel plugin and running with
maven camel:run
the camel.log file is produced as expeceted.
However, when packaging the camel routes and moving the jar to ActiveMQ, the log file is no longer created. I've checked the jars for slf4j, log4j and slf4j-log4j, and the versions are the same in ActiveMQ as in my pom.xml.
Any clues as to what I'm missing here?
EDIT: Just to clarify what I'm after here.
I've experienced issues on more than one occasaion where ActiveMQ is shutting down because there is something wrong with my camel routes, but I don't see any exceptions in the activemq logs, which makes debugging extremely time consuming. Today I had such an issue, and realised that while there was still no trace of error in the log, I got a stacktrace when just doing maven camel:run on my project. A simple example (really just an example, I know why this is happening, but I want it logged when running in ActiveMQ aswell!)
INFO | Apache Camel 2.12.2 (CamelContext: camel-1) is starting
INFO | StreamCaching is enabled on CamelContext: camel-1
INFO | JMX is enabled
INFO | Using EntityManagerFactory configured: org.springframework.orm.jpa.LocalEntityManagerFactoryBean#2127ee90
INFO | Using TransactionManager found in registry with id [transactionTemplate] org.springframework.orm.jpa.JpaTransactionManager#449f40f1
INFO | Apache Camel 2.12.2 (CamelContext: camel-1) is shutting down
INFO | Apache Camel 2.12.2 (CamelContext: camel-1) uptime 0.477 seconds
INFO | Apache Camel 2.12.2 (CamelContext: camel-1) is shutdown in 0.010 seconds
When deployed in ActiveMQ, this is the last line I see from Camel
But when running maven camel:run, I'm also seeing this:
INFO | Apache Camel 2.12.2 stopping
[ERROR] *************************************
[ERROR] Error occurred while running main from: org.apache.camel.spring.Main
[ERROR]
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.apache.camel.maven.RunMojo$1.run(RunMojo.java:486)
at java.lang.Thread.run(Thread.java:744)
Caused by: org.apache.camel.RuntimeCamelException: org.apache.camel.FailedToStartRouteException: Failed to start route XPriceChangeToRibRoute because of duplicate id detected: XPriceChangeToRibRoute. Please correct ids to be unique among all your routes.
at org.apache.camel.util.ObjectHelper.wrapRuntimeCamelException(ObjectHelper.java:1352)
...
So, what I really want is for the last part to be visible also when deployed in ActiveMQ, either in my activemq.log if possible, or as a separate log, e.g. camel.log.

Have a look at wrapper.log. That's where the STDOUT and STDERR should be found. Try to start ActiveMQ with the wrapper, e.g. for MacOS you could use:
apache-activemq-5.9.0/bin/macosx/activemq
Or if that's not an option, redirect STDOUT/STDERR to a log file.

Related

Bundle Apache Karaf Decanter Collector Prometheus in Waiting State

I'm deploying monitoring solution with Decanter Karaf and i've installed prometheus features: collectors and appenders. And i have java errors
ERROR | tures-3-thread-1 | PrometheusCollector | 581 - org.apache.karaf.decanter.collector.prometheus - 2.9.0 | bundle org.apache.karaf.decanter.collector.prometheus:2.9.0 (581)[org.apache.karaf.decanter.collector.prometheus.PrometheusCollector(30)] : The activate method has thrown an exception
java.lang.IllegalArgumentException: prometheus.url is mandatory in the configuration and the bundle org.apache.karaf.decanter.collector.prometheus is always in waiting state.
I added the prometheus url in the cfg file etc/org.apache.karaf.decanter.collector.prometheus.cfg but i have always the same problem.
According to the documentation that is the correct configuration.
Based on this little info I can only advise to debug, you might have made a simple configuration mistake.

How do I suppress INFO messages when using Kafka in Java?

I use Apache Kafka client in Java and now I'm getting a lot of messages with [INFO] mark. All the suggestions I've found on the Internet are of changing log4j output level. But I don't use log4j.
A small part of output:
[main] INFO org.apache.kafka.common.utils.AppInfoParser - Kafka version: 2.2.0
[main] INFO org.apache.kafka.common.utils.AppInfoParser - Kafka commitId: 05fcfde8f69b0349
[main] INFO org.apache.kafka.clients.consumer.KafkaConsumer - [Consumer clientId=consumer-1, groupId=group3] Subscribed to topic(s): test.topics.tasks
UPDATE:
I use org.apache.kafka:kafka-clients:2.2.0
But I don't use log4j.
Maybe you don't, but some library that you pull, probably does (for example, Spring).
You should consult the documentation for the framework that you use (if any), otherwise, you can add your own log4j.properties file into your classpath like so.
log4j.rootLogger=WARN, stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=[%d] %p %m (%c)%n
log4j.appender.stdout.Target=System.out
You can do this programmatically by adding this line in your code System.setProperty(org.slf4j.impl.SimpleLogger.DEFAULT_LOG_LEVEL_KEY, "off");
This is because Kafka is using sl4j for logging, so disabling sl4j logging will suppress info messages. If you wish to log for other levels/purposes, you can replace "off" with one of these: "trace", "debug", "info", "warn", "error" based on https://www.slf4j.org/api/org/slf4j/impl/SimpleLogger.html

Jetty Runner IDEA Community Logging

I am working on a project using Intellij IDEA Community, so I am using Jetty Runner to deploy my web application in localhost, everything is working ok, but I want to configure logs regarding Jetty, at server startup I see this kind of log :
14:50:20.516 [main] DEBUG o.eclipse.jetty.webapp.WebAppContext - isSystemResource==false org.springframework.expression.spel.ast.OpDec jar:file:/C:/Mario/development/spring/spring5/workspace/springsecurity/chapter02/chapter02.00-calendar/build/exploded/WEB-INF/lib/spring-expression-4.3.11.RELEASE.jar!/org/springframework/expression/spel/ast/OpDec.class
14:50:20.516 [main] DEBUG o.e.jetty.webapp.WebAppClassLoader - WAP webapp loaded class org.springframework.expression.spel.ast.OpDec
14:50:20.516 [main] DEBUG o.eclipse.jetty.webapp.WebAppContext - isSystemResource==false org.springframework.expression.spel.ast.OperatorNot jar:file:/C:/Mario/development/spring/spring5/workspace/springsecurity/chapter02/chapter02.00-calendar/build/exploded/WEB-INF/lib/spring-expression-4.3.11.RELEASE.jar!/org/springframework/expression/spel/ast/OperatorNot.class
14:50:20.517 [main] DEBUG o.e.jetty.webapp.WebAppClassLoader - WAP webapp loaded class org.springframework.expression.spel.ast.OperatorNot
1
I want to change the granularity from DEBUG to info regarding jetty server.
Put a jetty-logging.properties file in your resources folder and configure the logging there:
# Configure for System.err output
org.eclipse.jetty.util.log.class=org.eclipse.jetty.util.log.StdErrLog
# Configure StdErrLog to log all jetty namespace at default of WARN or above
org.eclipse.jetty.LEVEL=INFO
More info here: https://www.eclipse.org/jetty/documentation/9.4.x/configuring-logging.html

log4j2 in Wildfly 9

I use log4j2 as my default logging, when I run my webapp with Wildfly, My logs get wrapped as an INFO like follows:
17:28:31,127 INFO [stdout] (default task-6) DEBUG 2015-10-15 17:28:31,127 za.co.manticore.core.aspect.cacing.CachingAspect - Entering Caching Aspect for method getApplicationMeta
This is causing my logs to be cluttered, as all my logs are logged as INFO. How can I configure Wildfly to not do this. I have done some googleing but could not find an answer that worked.
I think, you should properly configure log4j2. It looks like currently it has console appender - try remove console appender from log4j2 config
Ok you can configure Wildfly not to wrap your stdout and stderr logs.
Run the following CLI commands
sh jboss-cli.sh --connect '/subsystem=logging/console-handler=JUST-PRINT:add(formatter="%s%E%n")'
sh jboss-cli.sh --connect '/subsystem=logging/logger=stderr:add(use-parent-handlers="false", handlers=[JUST-PRINT])'
sh jboss-cli.sh --connect '/subsystem=logging/logger=stdout:add(use-parent-handlers="false", handlers=[JUST-PRINT])'

"Camel is shutting down" when starting in ActiveMQ

I'm currently developing a Java DSL route, which will fetch a message from a JMS queue, process it, and put it in a database using JPA. Fairly simple really:
public void configure() {
from("{{ribMessage.source}}")
.split(xpath("/RibMessages/*"))
.streaming()
.process(new RibMessageToEntityProcessor())
.to("{{ribMessage.destination}}");
}
As you can see, I'm trying to use camel properties here, which I have defined in a properties file on my classpath:
ribMessage.source=activemq:queue:in.item_q
ribMessage.destination=jpa:com.axstores.aim.entities.XMLImport
The properties file is defined in spring like so:
<bean id="properties" class="org.apache.camel.component.properties.PropertiesComponent">
<property name="location" value="classpath:ribmessage.properties"/>
</bean>
I've updated the activemq config to include a camel.xml, and I've added my route package to the ActiveMQ camel.xml. And during startup, ActiveMQ is finding my route, but then it looks like it isn't able to find my property, and looks up URI {{ribMessage.source}} instead. This fails of course, and the next line in the log says that Camel is shutting down.
2014-02-01 23:31:20,278 | DEBUG | Searching for implementations of org.apache.camel.RoutesBuilder in packages: [com.axstores.aim] | org.apache.camel.impl.DefaultPackageScanClassResolver | main
2014-02-01 23:31:20,374 | DEBUG | Found: [class com.axstores.aim.routes.RibMessageToAimRoute] | org.apache.camel.impl.DefaultPackageScanClassResolver | main
...
2014-02-01 23:46:52,410 | TRACE | Starting service | org.apache.camel.support.ServiceSupport | main
2014-02-01 23:46:52,414 | TRACE | Getting endpoint with uri: {{ribMessage.source}} | org.apache.camel.spring.SpringCamelContext | main
2014-02-01 23:46:52,416 | INFO | Apache Camel 2.12.1 (CamelContext: camel) is shutting down | org.apache.camel.spring.SpringCamelContext | main
I suspect that I'm missing something in my config, because it seems to me like my spring config file is not being read at all.
Any clues? More info needed?
Full log for reference
Spring config
You need to add the camel-jpa component JAR to the classpath of the ActiveMQ broker. And as well what additional JARs you may need for JPA such as the JPA implementation and JDBC drivers and whatnot.
So with some help from the Claus and Peter gave, and some trial and error, I was finally able to get going ActiveMQ up and running, with my routes.
There was one major thing I missed in my config, which basically screwed up everything else. Active MQ was able to find my route through the config, but it still didn't seem to load my spring config.
I finally figured out that I had to add the following import statement to my ActiveMQ camel.xml, in order for it to load the spring config from my jar file.
<import resource="classpath:META-INF/spring/camel-context.xml"/>
Adding this allowed ActiveMQ to resolve my ribmessage.properties, as Peter mentioned in a comment above, this was not being done at all initially. This also loaded my JPA config, which revealed a bunch of missing jars, as Claus pointed out in the comment above.
For this project I'm using EclipseLink and Oracle 11g, so besides camel-jpa, I also had to add the follwing jars to the ActiveMQ classpath:
ojdbc7-12.1.0.1.jar
eclipselink-2.5.1.jar
spring-orm-3.2.4.RELEASE.jar
persistence-api-1.0.jar
spring-jdbc-3.2.4.RELEASE.jar
Hopefully someone can benefit from my (in)experiences.
I really only discovered Camel one week ago, and it seems to be an awesome framework for building integrations :-)

Categories