One Star

sl4j or log4j logging

Hi,
I tried configuring loggers in one of the pax.logging.cfg file, java.util.logging.properties files as below-
log4j.logger.com.mypackage.MyApp=DEBUG, out, stdout
in talend route java code-
org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(MyApp.class);
log.warn("sample log message");
the above statement does not log at any level ( WARN, DEBUG). Any idea? I get no logging errors as well Smiley Sad
Also tried installing tlog4j and tlogcatcher components but, they found to be not available in Mediation view.

  • ESB
8 REPLIES
Employee

Re: sl4j or log4j logging

Did you test inside the Talend Runtime (OSGi) or outside? Inside the Talend Runtime it should just work. You should not even need to adjust the logging config as you are using .warn which should always be logged.
One Star

Re: sl4j or log4j logging

I tested inside osgi container. I can see that loggers are working if implemented by -
org.apache.commons.logging.Log log = org.apache.commons.logging.LogFactory.getLog(MyApp.class);
if(log.isWarnEnabled())
log.warn("sample log message");
but, I want it with org.slf4j.Logger as I am using some talend components that implement the logger this way. Are there any jars I am missing?
I already put sl4j-api-1.6.1, sl4j-log4j-1.6.1, common-logging.jar, log4j-1.2.16.jar in cconfig.
I also tried without configuring the properties and without jars. This way, sl4j is defaulting to NOP implementation.
Employee

Re: sl4j or log4j logging

The problem may be exactly that you put the slf4j api in the config. As far as I know that means it is embedded into the jar. Probably that makes the slf4j invisble for pax logging. You can check the resulting jar of your route. It should not embed slf4j api and instead have an Import-Package for it.
One Star

Re: sl4j or log4j logging

How do I make slf4j api as Import-Package ? I am using Talend. The reference is not present in Import-Package.
Employee

Re: sl4j or log4j logging

I also saw that. I checked with the the dev team for the tooling. Currently it does not seem to be possible to use slf4j.
They are working on a solution. I hope we can at least add the import package statements to the manifest for the next bugfix release. For the longer term it is planned to allow users to specify their own imports.
Employee

Re: sl4j or log4j logging

You might try to use the Advanced tab on the cMessageEndpoint rather than the cConfig. The behavior for exporting dependencies is slightly different than with cConfig.
Employee

Re: sl4j or log4j logging

hmm, I don't seem to have any problem using slf4j within a cbean in 5.1.1. I assume the same would be true using routes developed with beans that were developed in Eclipse and imported into a Talend project I've attached links to a sample route (very trivial) that uses sl4j with log4j. It runs it both Studio and ESB runtime without problems. Perhaps I am misunderstanding the problem?
Here is the exported route http://eost.net/eost/slf4jTest/slf4jTest.zip
One Star

Re: sl4j or log4j logging

Where is the log4J configuration in Talend 5.4.1 Studio? It used to be in Preferences -> Talend -> Run/Debug -> Log4j in 5.2.2 now it's gone. I don't understand why Talend removes features and then not document the change.