Jan Eerdekens 10 Years Ago I got this to work for the most part, but can't seem to get MDC to work. I add values to the MDC and use a pattern that should print them, but no values get printed, but the rest of the log line does. Please sign in to reply. Reply as... Cancel Denis Signoretto Jan Eerdekens 10 Years Ago Hi Jan,happy to hear that you tryied and it works. I can confirm that MDC(Mapped Diagnostic Context) doesn't work using Liferay Logging Framework SLF4J Adapter (util-slf4j.jar). Looking at source code of org.slf4j.impl.StaticMDCBinder (https://github.com/liferay/liferay-portal/blob/6.2.0-ga1/util-slf4j/src/org/slf4j/impl/StaticMDCBinder.java) it returns a BasicMDCAdapter and as BasicMDCAdapter javadoc reports "can be used with logging systems that lack out-of-the-box MDC support". It seems it's still an unsupported feature.I've just seen, commented and voted your reported https://issues.liferay.com/browse/LPS-44869. Thanks,Denis. Please sign in to reply. Reply as... Cancel Denis Signoretto Denis Signoretto 10 Years Ago As Jan reported in https://issues.liferay.com/browse/LPS-44869 switching to slf4j-log4j12 MDC works as expected. Please sign in to reply. Reply as... Cancel Jan Eerdekens Denis Signoretto 10 Years Ago I tried some (very) quick debugging yesterday and found that stuff got put into the MDC correctly, but when the log message is being formatted the values aren't there anymore. Didn't have the time yet to delve in deeper to see what causes it. Please sign in to reply. Reply as... Cancel Denis Signoretto Jan Eerdekens 10 Years Ago - Edited I opened a feature request to add MDC (Mapped Diagnostic Context) support to Liferay Logging API (https://issues.liferay.com/browse/LPS-44900) and extend it to SLF4J Adapter (https://issues.liferay.com/browse/LPS-44869). Please sign in to reply. Reply as... Cancel
Denis Signoretto Jan Eerdekens 10 Years Ago Hi Jan,happy to hear that you tryied and it works. I can confirm that MDC(Mapped Diagnostic Context) doesn't work using Liferay Logging Framework SLF4J Adapter (util-slf4j.jar). Looking at source code of org.slf4j.impl.StaticMDCBinder (https://github.com/liferay/liferay-portal/blob/6.2.0-ga1/util-slf4j/src/org/slf4j/impl/StaticMDCBinder.java) it returns a BasicMDCAdapter and as BasicMDCAdapter javadoc reports "can be used with logging systems that lack out-of-the-box MDC support". It seems it's still an unsupported feature.I've just seen, commented and voted your reported https://issues.liferay.com/browse/LPS-44869. Thanks,Denis. Please sign in to reply. Reply as... Cancel Denis Signoretto Denis Signoretto 10 Years Ago As Jan reported in https://issues.liferay.com/browse/LPS-44869 switching to slf4j-log4j12 MDC works as expected. Please sign in to reply. Reply as... Cancel Jan Eerdekens Denis Signoretto 10 Years Ago I tried some (very) quick debugging yesterday and found that stuff got put into the MDC correctly, but when the log message is being formatted the values aren't there anymore. Didn't have the time yet to delve in deeper to see what causes it. Please sign in to reply. Reply as... Cancel
Denis Signoretto Denis Signoretto 10 Years Ago As Jan reported in https://issues.liferay.com/browse/LPS-44869 switching to slf4j-log4j12 MDC works as expected. Please sign in to reply. Reply as... Cancel
Jan Eerdekens Denis Signoretto 10 Years Ago I tried some (very) quick debugging yesterday and found that stuff got put into the MDC correctly, but when the log message is being formatted the values aren't there anymore. Didn't have the time yet to delve in deeper to see what causes it. Please sign in to reply. Reply as... Cancel
Denis Signoretto Jan Eerdekens 10 Years Ago - Edited I opened a feature request to add MDC (Mapped Diagnostic Context) support to Liferay Logging API (https://issues.liferay.com/browse/LPS-44900) and extend it to SLF4J Adapter (https://issues.liferay.com/browse/LPS-44869). Please sign in to reply. Reply as... Cancel
abdo koptan 9 Years Ago Hi Denis, I have follow you steps but it's not working for me, i am using liferay 6.1 - Jboss 7.1Thank you Please sign in to reply. Reply as... Cancel
Eric Soucy 9 Years Ago How would you log from a managedbean in a jsf portlet?what import statements are needed ? Please sign in to reply. Reply as... Cancel
Eric Soucy 9 Years Ago Hi,It's working partially for me, I see my log output in the console, and in the liferay.log filemy custom rolling appender file gets created but my logout output is not in the file.I do see other lines being logged in the file, but not the ones I logged from my managed bean. Please sign in to reply. Reply as... Cancel Denis Signoretto Eric Soucy 9 Years Ago Hi Eric,it seems, you have setup correclty the Liferay logging system to log on a separate file but you are not sending log to Liferay logging system. Check your slf4j imports in your class and use an slf4j Logger instance for logging.import org.slf4j.Logger;import org.slf4j.LoggerFactory;You can find a working slf4j sample portlet here: https://github.com/denissignoretto/slf4j-logging-sample-portletHope it can help!Denis. Please sign in to reply. Reply as... Cancel
Denis Signoretto Eric Soucy 9 Years Ago Hi Eric,it seems, you have setup correclty the Liferay logging system to log on a separate file but you are not sending log to Liferay logging system. Check your slf4j imports in your class and use an slf4j Logger instance for logging.import org.slf4j.Logger;import org.slf4j.LoggerFactory;You can find a working slf4j sample portlet here: https://github.com/denissignoretto/slf4j-logging-sample-portletHope it can help!Denis. Please sign in to reply. Reply as... Cancel
Thomas Hii 9 Years Ago Hi Denis,The example is working great for Liferay 6.2 running on Tomcat. However when I tried it with Liferay 6.2 running on JBoss 7 or JBoss EAP 6, the log file is created but nothing is written to it. Any idea on what might cause this problem? Please sign in to reply. Reply as... Cancel Thomas Hii Thomas Hii 9 Years Ago Finally figured out that the problem is due to JBoss class loading. By default, JBoss always load its version of log4j and slf4j. These need to be excluded via the jboss-deployment-structure.xml file. App Manager seems to generate this file during deployment, but org.slf4j is not in the exclusion list. After adding org.slf4j, the custom logging works nicely on JBoss 7.1 and JBoss EAP 6.2. Please sign in to reply. Reply as... Cancel Denis Signoretto Thomas Hii 9 Years Ago Hi Tomas,thanks for sharing this info! Please sign in to reply. Reply as... Cancel
Thomas Hii Thomas Hii 9 Years Ago Finally figured out that the problem is due to JBoss class loading. By default, JBoss always load its version of log4j and slf4j. These need to be excluded via the jboss-deployment-structure.xml file. App Manager seems to generate this file during deployment, but org.slf4j is not in the exclusion list. After adding org.slf4j, the custom logging works nicely on JBoss 7.1 and JBoss EAP 6.2. Please sign in to reply. Reply as... Cancel Denis Signoretto Thomas Hii 9 Years Ago Hi Tomas,thanks for sharing this info! Please sign in to reply. Reply as... Cancel
Denis Signoretto Thomas Hii 9 Years Ago Hi Tomas,thanks for sharing this info! Please sign in to reply. Reply as... Cancel
Alberto de Francisco Martín 8 Years Ago Hi, DenisThank you Denis for the information.ThanksAlberto de Francisco Please sign in to reply. Reply as... Cancel
Nagendra Kumar Busam 8 Years Ago Thank you very much sharing details. In your portlet you are using slf4j - where does Liferay's slf4j layer came in? Please sign in to reply. Reply as... Cancel Denis Signoretto Nagendra Kumar Busam 8 Years Ago Hi Nagendra,Liferay SLF4J layer came in with util-slf4j.jar bridge that implement the slf4j logging adapter for Liferay logging interface. Please sign in to reply. Reply as... Cancel
Denis Signoretto Nagendra Kumar Busam 8 Years Ago Hi Nagendra,Liferay SLF4J layer came in with util-slf4j.jar bridge that implement the slf4j logging adapter for Liferay logging interface. Please sign in to reply. Reply as... Cancel
parikshit sharma 8 Years Ago Hi Denis,As per your blog I am trying to implement the logs for custom portlet on bundled JBOSS server 7.1.1, but it's generating the blank log file, could you please guide me what I am missing. Below are the configurations I have done to implement it.1.Added the dependencies for slf4j-api.jar and util-slf4j.jar file in pom.xml.2.If I add the log4j.jar dependency in pom.xml , at the time of deployment it raise below exception. java.lang.ClassCastException: org.apache.log4j.EnhancedPatternLayout cannot be cast to org.apache.log4j.LayoutI searched for it , and found that by adding the log4j.jar in portlet I am initializing it again, as it is already initialized by JBOSS. So I added below configurationAdded jboss-deployment-structure.xml ,with below configuration <exclusions> <module name="javaee.api"></module> <module name="org.apache.log4j"></module> <module name="org.slf4j"></module> <module name="org.slf4j.impl"></module> <module name="org.jboss.logging"></module> <module name="org.jboss.logging.jul-to-slf4j-stub"></module> <module name="org.jboss.logmanager"></module> <module name="org.jboss.logmanager.log4j"></module> </exclusions>But still it raise the same exception.Thanks.Parikshit Please sign in to reply. Reply as... Cancel
sandeep g 8 Years Ago It is also not working for me on jboss EAP 6.2. I have excluded all the modules still no luck.<exclusions> <module name="javaee.api" /> <module name="org.apache.log4j" /> <module name="org.apache.commons.logging" /> <module name="org.jboss.logging" /> <module name="org.jboss.logging.jul-to-slf4j-stub" /> <module name="org.jboss.logmanager" /> <module name="org.jboss.logmanager.log4j" /> <module name="org.slf4j" /> <module name="org.slf4j.impl" /> </exclusions> Please sign in to reply. Reply as... Cancel