Configuring logback for shared engine in tomcat


#1

I’m trying to send the log messages to a custom file using logback in my shared engine. Following the documentation I’ve done the following:

Add the logback dependency

I included logback-classic1.2.3.jar in …/webapps/camunda-engine/WEB-INF/lib

Add a file named logback.xml

I prepared my logback file based on the configuration example and I put my file in …/webapps/camunda-engine/WEB-INF/classes (following the logback documentation)

Also make sure to make mybatis use SLF4J as logger by adding
LogFactory.useSlf4jLogging();
somewhere in your setup code.

This I have no idea what is talking about. I have no setup code, I just deploy the war.

Can someone expand a little the explanation in the documentation?

Thanks in advance,
Gonzalo


Camunda JSON Logging for shared engine: solved!
#2

By the way, my goal is to log the code I developed to be used as JavaDelegates. I’m trying to configure camunda’s logs using logback in order to do set the logs from “delegates.XXXX” to a custom file. If there is an easier way to achieve this, will work just as well for me.

Cheers.


#3

Hi @gcalvo,

I understand your last post that you would like a single log file with log output of both the process engine and your application. Is that correct?

Note that the prebuilt Camunda Tomcat distribution already includes an SLF4J implementation. This is slf4-jdk14.jar in ${TOMCAT_HOME}/lib and redirects the engine’s SLF4J calls to Java util logging, for which Tomcat has a custom implementation with a global config file at ${TOMCAT_HOME}/conf/logging.properties, see https://tomcat.apache.org/tomcat-8.0-doc/logging.html.

Cheers,
Thorben


#4

Hi @thorben, thanks for your reply.

I want Camunda logs in one file. Including the logs Camunda produces by calling my custom JavaDelegates code.

I’ll use Java Util Logging if there is no other way, but I wanted to use logback to use the same technology all our webapps use. The thing that bugs me is the following:

I managed to include logback in camunda. Then removed the slf4j-jdk14.jar and included jul-to-slf4j bridge. Now all Camunda logs should be directed to logback since the legacy (jboss, camunda-engine-rest…) is redirected and the standard camunda logs already use slf4j right?

But only legacy logs are being redirect using logback. This is what my log file looks like:

2017-11-14 13:52:09,401 [http-bio-8080-exec-2] DEBUG org.jboss.resteasy.core.SynchronousDispatcher - PathInfo: /message
2017-11-14 13:52:09,722 [http-bio-8080-exec-6] DEBUG org.jboss.resteasy.core.SynchronousDispatcher - PathInfo: /process-definition/Process_1003:9:353239a9-b8b3-11e7-9bff-d8cb8ae5ad7b/start

Every entry is from “org.jboss.resteasy.X”

What am I missing here?

Cheers.

Edit: By the way, the logback configuration I’m using for testing is “send everything you catch to this file”. (One root logger at trace level redirected to a single file).


#5

Sounds like a good plan. At least for those log statements that the engine makes and that are not made in the classloading context of your application, logback.xml in your application will not be useful I think. I just tried the following things myself and was able to get my logback configuration to work:

  1. Add logback-core and logback-classic jars to global lib folder
  2. Remove slf4j-jdk14
  3. Edit ${TOMCAT_HOME}/conf/catalina.properties and add the following property: logback.configurationFile=<path to config> and my logback config was used for all the engine’s log statements that use SLF4J.

In order to also redirect Tomcat’s internal logging, we would need to include jul-to-slf4j (like you did) and then configure ${TOMCAT_HOME}/conf/logging.properties to use the slf4j bridge handler as described in https://www.slf4j.org/api/org/slf4j/bridge/SLF4JBridgeHandler.html.


Logback logging Camunda Engine
#6

It worked. I certainly don’t understand why, it works.

Really appreciate your help @thorben, this helps me a lot.

I’m still curious as why the logback libs in the shared path makes it work and inside camunda webapp instead doesn’t.

And why pointing to the logback file from catalina.properties works but leaving it in the classpath of the app doesn’t (even the logback file gets read). This has the drawback of the rest of logback.xml files from the other webapps in tomcat being ingnored, but I can work around that.

Thanks again,
Gonzalo.


#7

Hi Gonzalo,

Ah, now I realize you put the libs in the webapp :slight_smile:

Most of the engine’s log statements are part of camunda-engine.jar (and not the webapp), which is on the shared classpath. The loggers are static members of those classes and instantiated when Tomcat starts up (which loads the respective classes), so the logger implementations must be available on the shared path as well.

Cheers,
Thorben


#9

@thorben can you explain how you used https://www.slf4j.org/api/org/slf4j/bridge/SLF4JBridgeHandler.html ? When i use it as per the docs, I get a class not found exception. I have tried brining in:

 <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>jul-to-slf4j</artifactId>
            <version>1.7.25</version>
        </dependency>

through a engine plugin as a dep, as well as just injecting the jar into the shared lib folder (camunda/lib). Using Tomcat 7.9. Using the logging.properties file and the camunda docker distribution. Basically just overwriting the logging.properties file in camunda/conf.

Thoughts?