Daniele Baggio 11 Years Ago In many cases this is necessary, thank you Please sign in to reply. Reply as... Cancel
David García González 11 Years Ago I always used the log com.liferay.portal.kernel.log.Log. like this:private static Log logger = LogFactoryUtil.getLog(Clase.class);What is the difference between them and what is the recommended log to log our developed portlets?Thanks. Please sign in to reply. Reply as... Cancel
István Székely 11 Years Ago I don't recommend using the ConsoleAppender in production environment at all. It uses the System.out which will be redirected to catalina.out in Tomcat. Since this method does not use the logging facility, this file can't be rotated or compressed. The catalina.out will grow huge very quickly.Unfortunately we have a legacy project which does not use proper logging. In this environment we have to shut down Tomcat every night to rotate and compress the catalina.out file. Please sign in to reply. Reply as... Cancel Kamesh Sampath István Székely 11 Years Ago Thanks and good information.@DavidUsing the logger from Liferay API classes has couple of disadvantages 1. It affects portability2.If any chanegs made to the Liferay logging API may have impact on the custom Portlet logging Please sign in to reply. Reply as... Cancel
Kamesh Sampath István Székely 11 Years Ago Thanks and good information.@DavidUsing the logger from Liferay API classes has couple of disadvantages 1. It affects portability2.If any chanegs made to the Liferay logging API may have impact on the custom Portlet logging Please sign in to reply. Reply as... Cancel
Brett Swaim 11 Years Ago @DavidA lot of people use that, and there really isn't anything wrong with that. There are plusses and minuses to everything.Pros: You can adjust the logging on the fly in the consoleYou are guaranteed future compatibility if Liferay were to ever stop using log4j for some reasonYou don't have to setup anything, it's extremely easy to just log and goCons:Somewhat inflexible configs for storing logs anywhere other than the consoleAs @Kamesh said, it's Liferay specific. I always hear that argument though, and I've yet to actually see somebody go through all the work of building out a system on Liferay, then saying oh never mind and taking all those portlets and moving them to another system. In theory, yes it's Liferay specific, in reality, I've never really seen it matter. Please sign in to reply. Reply as... Cancel
Brett Swaim 11 Years Ago @KameshIn regards to your statement 2, that's actually the reason I would say TO use it. You are safe, because you are using our logging system. My worry would be if you are depending on log4j and we change that, THEN you might have issues depending on what was changed. The coolest part about our utils is that we keep you insulated from future changes. Please sign in to reply. Reply as... Cancel Kamesh Sampath Brett Swaim 11 Years Ago Thanks Brett, ideally my argument with #2 I agree its a theoriticaly statement but i dont say its not inevitable though i have seen clients doing the same for may portals .. I would rather put this way when you put this way when i use Liferay logger utils then formats of logging , levels are controlled by the Liferay server either i have to use the *-ext mechanisms to override them or use the Liferay admin console. If we tend you use the way said above we are in absolute control of the logging. Please sign in to reply. Reply as... Cancel
Kamesh Sampath Brett Swaim 11 Years Ago Thanks Brett, ideally my argument with #2 I agree its a theoriticaly statement but i dont say its not inevitable though i have seen clients doing the same for may portals .. I would rather put this way when you put this way when i use Liferay logger utils then formats of logging , levels are controlled by the Liferay server either i have to use the *-ext mechanisms to override them or use the Liferay admin console. If we tend you use the way said above we are in absolute control of the logging. Please sign in to reply. Reply as... Cancel
Brett Swaim 11 Years Ago @IstvánI agree with you in a production environment, but for any other env I love being able to tail just one file and seeing everything fly by. I basically have a monitor dedicated to production logs so I can see if anything happens that shouldn't. I'm not 100% sure how they do it, but the client that I work for has a way to blow away the catalina.out file nightly without bouncing the server. I'll see if I can figure out how today and post it here for you. Please sign in to reply. Reply as... Cancel István Székely Brett Swaim 11 Years Ago Thanks, that would be great. Earlier I google'd it but others also said there was no other solution. Please sign in to reply. Reply as... Cancel Brett Swaim István Székely 11 Years Ago - Edited @István They have a cron job that does this (as the deploy user)cat /dev/null > /path/to/liferay/bundles/tomcat-7.0.21/logs/catalina.outI just tested it locally and it worked perfectly. Give it a shot! Please sign in to reply. Reply as... Cancel Remis Baima Brett Swaim 11 Years Ago There is one small issue with this approach (at least in 6.0.12 EE). When you use Log4j inside of a ServiceBuilder Impl class (i.e. *LocalServiceImpl.java) you get the Exception described here: http://issues.liferay.com/browse/LPS-9376But anyway... the workaround given in the issue comment will "solve" the problem. Please sign in to reply. Reply as... Cancel Brett Swaim Remis Baima 11 Years Ago Right, I actually just ran into that issue myself! I just added:-Dlog4j.ignoreTCL=trueto setenv.sh and that cleaned it up for me. The error this fixes is:log4j:ERROR A "org.apache.log4j.xml.DOMConfigurator" object is not assignable to a "org.apache.log4j.spi.Configurator" variable.log4j:ERROR The class "org.apache.log4j.spi.Configurator" was loaded by log4j:ERROR [WebappClassLoader context: /cisco-webservices-hook delegate: false repositories: /WEB-INF/classes/----------> Parent Classloader:org.apache.catalina.loader.StandardClassLoader@3e4a9a7d] whereas object of type log4j:ERROR "org.apache.log4j.xml.DOMConfigurator" was loaded by [WebappClassLoader context: delegate: false repositories: /WEB-INF/classes/----------> Parent Classloader:org.apache.catalina.loader.StandardClassLoader@3e4a9a7d].log4j:ERROR Could not instantiate configurator [org.apache.log4j.xml.DOMConfigurator]. Please sign in to reply. Reply as... Cancel
István Székely Brett Swaim 11 Years Ago Thanks, that would be great. Earlier I google'd it but others also said there was no other solution. Please sign in to reply. Reply as... Cancel Brett Swaim István Székely 11 Years Ago - Edited @István They have a cron job that does this (as the deploy user)cat /dev/null > /path/to/liferay/bundles/tomcat-7.0.21/logs/catalina.outI just tested it locally and it worked perfectly. Give it a shot! Please sign in to reply. Reply as... Cancel Remis Baima Brett Swaim 11 Years Ago There is one small issue with this approach (at least in 6.0.12 EE). When you use Log4j inside of a ServiceBuilder Impl class (i.e. *LocalServiceImpl.java) you get the Exception described here: http://issues.liferay.com/browse/LPS-9376But anyway... the workaround given in the issue comment will "solve" the problem. Please sign in to reply. Reply as... Cancel Brett Swaim Remis Baima 11 Years Ago Right, I actually just ran into that issue myself! I just added:-Dlog4j.ignoreTCL=trueto setenv.sh and that cleaned it up for me. The error this fixes is:log4j:ERROR A "org.apache.log4j.xml.DOMConfigurator" object is not assignable to a "org.apache.log4j.spi.Configurator" variable.log4j:ERROR The class "org.apache.log4j.spi.Configurator" was loaded by log4j:ERROR [WebappClassLoader context: /cisco-webservices-hook delegate: false repositories: /WEB-INF/classes/----------> Parent Classloader:org.apache.catalina.loader.StandardClassLoader@3e4a9a7d] whereas object of type log4j:ERROR "org.apache.log4j.xml.DOMConfigurator" was loaded by [WebappClassLoader context: delegate: false repositories: /WEB-INF/classes/----------> Parent Classloader:org.apache.catalina.loader.StandardClassLoader@3e4a9a7d].log4j:ERROR Could not instantiate configurator [org.apache.log4j.xml.DOMConfigurator]. Please sign in to reply. Reply as... Cancel
Brett Swaim István Székely 11 Years Ago - Edited @István They have a cron job that does this (as the deploy user)cat /dev/null > /path/to/liferay/bundles/tomcat-7.0.21/logs/catalina.outI just tested it locally and it worked perfectly. Give it a shot! Please sign in to reply. Reply as... Cancel Remis Baima Brett Swaim 11 Years Ago There is one small issue with this approach (at least in 6.0.12 EE). When you use Log4j inside of a ServiceBuilder Impl class (i.e. *LocalServiceImpl.java) you get the Exception described here: http://issues.liferay.com/browse/LPS-9376But anyway... the workaround given in the issue comment will "solve" the problem. Please sign in to reply. Reply as... Cancel Brett Swaim Remis Baima 11 Years Ago Right, I actually just ran into that issue myself! I just added:-Dlog4j.ignoreTCL=trueto setenv.sh and that cleaned it up for me. The error this fixes is:log4j:ERROR A "org.apache.log4j.xml.DOMConfigurator" object is not assignable to a "org.apache.log4j.spi.Configurator" variable.log4j:ERROR The class "org.apache.log4j.spi.Configurator" was loaded by log4j:ERROR [WebappClassLoader context: /cisco-webservices-hook delegate: false repositories: /WEB-INF/classes/----------> Parent Classloader:org.apache.catalina.loader.StandardClassLoader@3e4a9a7d] whereas object of type log4j:ERROR "org.apache.log4j.xml.DOMConfigurator" was loaded by [WebappClassLoader context: delegate: false repositories: /WEB-INF/classes/----------> Parent Classloader:org.apache.catalina.loader.StandardClassLoader@3e4a9a7d].log4j:ERROR Could not instantiate configurator [org.apache.log4j.xml.DOMConfigurator]. Please sign in to reply. Reply as... Cancel
Remis Baima Brett Swaim 11 Years Ago There is one small issue with this approach (at least in 6.0.12 EE). When you use Log4j inside of a ServiceBuilder Impl class (i.e. *LocalServiceImpl.java) you get the Exception described here: http://issues.liferay.com/browse/LPS-9376But anyway... the workaround given in the issue comment will "solve" the problem. Please sign in to reply. Reply as... Cancel Brett Swaim Remis Baima 11 Years Ago Right, I actually just ran into that issue myself! I just added:-Dlog4j.ignoreTCL=trueto setenv.sh and that cleaned it up for me. The error this fixes is:log4j:ERROR A "org.apache.log4j.xml.DOMConfigurator" object is not assignable to a "org.apache.log4j.spi.Configurator" variable.log4j:ERROR The class "org.apache.log4j.spi.Configurator" was loaded by log4j:ERROR [WebappClassLoader context: /cisco-webservices-hook delegate: false repositories: /WEB-INF/classes/----------> Parent Classloader:org.apache.catalina.loader.StandardClassLoader@3e4a9a7d] whereas object of type log4j:ERROR "org.apache.log4j.xml.DOMConfigurator" was loaded by [WebappClassLoader context: delegate: false repositories: /WEB-INF/classes/----------> Parent Classloader:org.apache.catalina.loader.StandardClassLoader@3e4a9a7d].log4j:ERROR Could not instantiate configurator [org.apache.log4j.xml.DOMConfigurator]. Please sign in to reply. Reply as... Cancel
Brett Swaim Remis Baima 11 Years Ago Right, I actually just ran into that issue myself! I just added:-Dlog4j.ignoreTCL=trueto setenv.sh and that cleaned it up for me. The error this fixes is:log4j:ERROR A "org.apache.log4j.xml.DOMConfigurator" object is not assignable to a "org.apache.log4j.spi.Configurator" variable.log4j:ERROR The class "org.apache.log4j.spi.Configurator" was loaded by log4j:ERROR [WebappClassLoader context: /cisco-webservices-hook delegate: false repositories: /WEB-INF/classes/----------> Parent Classloader:org.apache.catalina.loader.StandardClassLoader@3e4a9a7d] whereas object of type log4j:ERROR "org.apache.log4j.xml.DOMConfigurator" was loaded by [WebappClassLoader context: delegate: false repositories: /WEB-INF/classes/----------> Parent Classloader:org.apache.catalina.loader.StandardClassLoader@3e4a9a7d].log4j:ERROR Could not instantiate configurator [org.apache.log4j.xml.DOMConfigurator]. Please sign in to reply. Reply as... Cancel
Nagendra Kumar Busam 11 Years Ago Thanks for sharing, good info Please sign in to reply. Reply as... Cancel
Denis Signoretto 11 Years Ago Hi Brett,thanks for your article I found it really useful. Can you explain me why, even though in my sources are not included, after a portlet deployment I found the following log4j and commons-logging related files? (it's a dependecy to get Liferay logging works)?WEB-INF\lib\log4j.jarWEB-INF\lib\commons-logging.jarWEB-INF\classes\log4j.propertiesWEB-INF\classes\logging.propertiesThanks,Denis. Please sign in to reply. Reply as... Cancel Denis Signoretto Denis Signoretto 10 Years Ago I answer by myself to my previous question. Duting auto deployment Liferay prepare a new "real" war package that will be deployed to your application server. Auto deployment adds by default portal tld, portal dependecies jar and log4j and common logging jars.If you want to avoid it, from Liferay 6.1, you can disable log4j and common logging using these properties: auto.deploy.copy.log4j=false and auto.deploy.copy.commons.logging=false Please sign in to reply. Reply as... Cancel
Denis Signoretto Denis Signoretto 10 Years Ago I answer by myself to my previous question. Duting auto deployment Liferay prepare a new "real" war package that will be deployed to your application server. Auto deployment adds by default portal tld, portal dependecies jar and log4j and common logging jars.If you want to avoid it, from Liferay 6.1, you can disable log4j and common logging using these properties: auto.deploy.copy.log4j=false and auto.deploy.copy.commons.logging=false Please sign in to reply. Reply as... Cancel
Samujjwal Sahu 10 Years Ago <rollingPolicy class="org.apache.log4j.rolling.TimeBasedRollingPolicy"> <param name="FileNamePattern" value="../../logs/portlet-name.%d{yyyy-MM-dd}.log" /> </rollingPolicy>The <appender> tag is not accepting this <rollingPolicy> tag in Eclipse. The content of element type "appender" must match "(errorHandler?,param*,layout?,filter*,appender-ref*)".This is the error that it is showing. Please sign in to reply. Reply as... Cancel
Péter Borkuti 10 Years Ago Thank you for this info.I have used it for a hook, and worked.Péter Please sign in to reply. Reply as... Cancel
Vishal Srivastava 9 Years Ago One of the way is this->-create two files under/tomcat-7.0.40/webapps/ROOT/WEB-INF/classes/META-INF1. portal-log4j-ext.xml <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE log4j:configuration SYSTEM "log4j.dtd"> <log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/"> <appender name="MY_APPENDER" class="org.apache.log4j.RollingFileAppender"> <param name="File" value="${catalina.home}/logs/log_name.log"/> <param name="MaxFileSize" value="10000KB"/> <param name="MaxBackupIndex" value="10"/> <layout class="org.apache.log4j.PatternLayout"> <param name="ConversionPattern" value="----- %n%d{yyyy/MM/dd HH:mm:ss} %p%n%l [%x][%t] %n%m%n" /> </layout> </appender> <root> <priority value="INFO" /> <appender-ref ref="CONSOLE" /> <!-- This being the default appender inside portal-log4j.xml --> <appender-ref ref="MY_APPENDER" /> </root> </log4j:configuration>2. log4j.dtdCopy code from->https://github.com/liferay/liferay-portal/blob/master/portal-impl/test/META-INF/log4j.dtdNote-: creating portal-log4j-ext.xml instead of log4j.xml is best in practice as it override portal-log4j.properties file. Please sign in to reply. Reply as... Cancel
Chirag M Gurav 8 Years Ago Hi First of all thanks for such a helpful post,i have implemented log4j in this way and its working fine in for single portlet but when i try same implementation in more then one portlet in same plugin sdk and its not working.for each and every portlet wise logs, is there any other configuration ? Please sign in to reply. Reply as... Cancel Brett Swaim Chirag M Gurav 8 Years Ago As long as the portlet name differs in your xml, it should be fine. Do you get any errors or does logging just totally stop working? Please sign in to reply. Reply as... Cancel Chirag M Gurav Brett Swaim 8 Years Ago given below error i am getting in console.log4j:ERROR A "org.apache.log4j.xml.DOMConfigurator" object is not assignable to a "org.apache.log4j.spi.Configurator" variable.log4j:ERROR The class "org.apache.log4j.spi.Configurator" was loaded bylog4j:ERROR [WebappClassLoader context: /manage-portlet delegate: false repositories: /WEB-INF/classes/----------> Parent Classloader:org.apache.catalina.loader.StandardClassLoader@53dc5341] whereas object of typelog4j:ERROR "org.apache.log4j.xml.DOMConfigurator" was loaded by [WebappClassLoader context: delegate: false repositories: /WEB-INF/classes/----------> Parent Classloader:org.apache.catalina.loader.StandardClassLoader@53dc5341where i have follow the same steps which you have mention in the blog. Please sign in to reply. Reply as... Cancel
Brett Swaim Chirag M Gurav 8 Years Ago As long as the portlet name differs in your xml, it should be fine. Do you get any errors or does logging just totally stop working? Please sign in to reply. Reply as... Cancel Chirag M Gurav Brett Swaim 8 Years Ago given below error i am getting in console.log4j:ERROR A "org.apache.log4j.xml.DOMConfigurator" object is not assignable to a "org.apache.log4j.spi.Configurator" variable.log4j:ERROR The class "org.apache.log4j.spi.Configurator" was loaded bylog4j:ERROR [WebappClassLoader context: /manage-portlet delegate: false repositories: /WEB-INF/classes/----------> Parent Classloader:org.apache.catalina.loader.StandardClassLoader@53dc5341] whereas object of typelog4j:ERROR "org.apache.log4j.xml.DOMConfigurator" was loaded by [WebappClassLoader context: delegate: false repositories: /WEB-INF/classes/----------> Parent Classloader:org.apache.catalina.loader.StandardClassLoader@53dc5341where i have follow the same steps which you have mention in the blog. Please sign in to reply. Reply as... Cancel
Chirag M Gurav Brett Swaim 8 Years Ago given below error i am getting in console.log4j:ERROR A "org.apache.log4j.xml.DOMConfigurator" object is not assignable to a "org.apache.log4j.spi.Configurator" variable.log4j:ERROR The class "org.apache.log4j.spi.Configurator" was loaded bylog4j:ERROR [WebappClassLoader context: /manage-portlet delegate: false repositories: /WEB-INF/classes/----------> Parent Classloader:org.apache.catalina.loader.StandardClassLoader@53dc5341] whereas object of typelog4j:ERROR "org.apache.log4j.xml.DOMConfigurator" was loaded by [WebappClassLoader context: delegate: false repositories: /WEB-INF/classes/----------> Parent Classloader:org.apache.catalina.loader.StandardClassLoader@53dc5341where i have follow the same steps which you have mention in the blog. Please sign in to reply. Reply as... Cancel