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?
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.
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.
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:
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).
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:
Add logback-core and logback-classic jars to global lib folder
Remove slf4j-jdk14
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 SLF4JBridgeHandler (SLF4J 2.0.1 API).
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.
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.
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.