Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Ben Carson
Custom logging in LR6.1 disappears after restart
September 4, 2012 11:15 AM
Answer

Ben Carson

Rank: Junior Member

Posts: 25

Join Date: January 9, 2012

Recent Posts

I am developing a portlet and have several debug statements included throughout my work. I followed the instructions here to get my debug statements to display in the log. Everything works fine...until I restart my server. Upon restarting, my custom logging setup disappears, and I have to go back into the Liferay Server Admin console to recreate the com.company.terms.portlet = DEBUG custom log level.
Is there a more "permanent" way of doing this, perhaps by providing this custom logging in the portal-ext.properties file or a properties file within my project?

Thanks.

Ben
David H Nebinger
RE: Custom logging in LR6.1 disappears after restart
July 6, 2012 12:40 PM
Answer

David H Nebinger

Community Moderator

Rank: Liferay Legend

Posts: 11295

Join Date: September 1, 2006

Recent Posts

There is not a way that is built in.

However, it is actually pretty easy to do...

1. Create your own startup action. For this guy to work (in the way I'm outlining below), you need to be able to use portal-impl.jar. I created mine directly in the source and copied the class into the ROOT/WEB-INF/classes directory, but it might also work from an EXT plugin:

 1package com.example;
 2
 3import com.liferay.portal.kernel.events.SimpleAction;
 4import com.liferay.portal.util.PropsUtil;
 5import com.liferay.util.log4j.Log4JUtil;
 6import java.util.Properties;
 7import org.apache.log4j.Level;
 8
 9public class LoggingStartupAction extends SimpleAction {
10    public void run(final String[] ids) {
11        // grab any values in the properties file(s) that start with "portal.logging." as these
12        // are the guys we want to use for new logging properties.
13        Properties props = PropsUtil.getProperties("portal.logging.", true);
14
15        if ((props == null) || (props.isEmpty())) {
16            // there are no logging properties defined
17            return;
18        }
19
20        // If we get here we have at least one logging property to deal with.
21        String priority;
22
23        for (String loggerName : props.stringPropertyNames()) {
24            // get the priority defined for the logger
25            priority = props.getProperty(loggerName, Level.INFO.toString());
26
27            // update the log4j stuff using Liferay's API...
28            Log4JUtil.setLevel(loggerName, priority);
29        }
30
31        // Done!
32    }
33}


2. In your portal-ext.properties, set up the global startup action event handlers...

1global.startup.events=com.liferay.portal.events.GlobalStartupAction,com.example.LoggingStartupAction


3. In your portal-ext.properties, define the loggers you want to apply at startup... You can either define new ones or change the logging levels for built-in ones:

1portal.logging.com.example=DEBUG
2portal.logging.com.example.util=INFO
3portal.logging.com.liferay.jdbc=INFO


That should do it!
David H Nebinger
RE: Custom logging in LR6.1 disappears after restart
July 6, 2012 12:45 PM
Answer

David H Nebinger

Community Moderator

Rank: Liferay Legend

Posts: 11295

Join Date: September 1, 2006

Recent Posts

The beauty of this method is that it is based upon the portal-ext.properties file. So if you have multiple environments (dev, test, prod) each already has their own portal-ext.properties, so the logging is also set up individually per environment.
Juan Gonzalez
RE: Custom logging in LR6.1 disappears after restart
July 7, 2012 2:37 AM
Answer

Juan Gonzalez

LIFERAY STAFF

Rank: Liferay Legend

Posts: 2856

Join Date: October 28, 2008

Recent Posts

Ben Carson:
I am developing a portlet and have several debug statements included throughout my work. I followed the instructions here to get my debug statements to display in the log. Everything works fine...until I restart my server. Upon restarting, my custom logging setup disappears, and I have to go back into the Liferay Server Admin console to recreate the com.company.terms.portlet = DEBUG custom log level.
Is there a more "permanent" way of doing this, perhaps by providing this custom logging in the portal-ext.properties file or a properties file within my project?

Thanks.

Ben


You can add it in portal-log4j.xml so it will persist after restarts.
Hitoshi Ozawa
RE: Custom logging in LR6.1 disappears after restart
July 7, 2012 7:16 AM
Answer

Hitoshi Ozawa

Rank: Liferay Legend

Posts: 7949

Join Date: March 23, 2010

Recent Posts

You mean portal-log4j-ext.xml

See the following wiki page.
http://www.liferay.com/community/wiki/-/wiki/Main/How+to+configure+the+logs+in+Liferay

portal-log4j.xml is in the portal-impl\src\META-INF in liferay source file.

If you're using JBoss as in most of my production environment, there's some additional notes in the wiki page.
Ben Carson
RE: Custom logging in LR6.1 disappears after restart
July 9, 2012 7:51 AM
Answer

Ben Carson

Rank: Junior Member

Posts: 25

Join Date: January 9, 2012

Recent Posts

David, Juan, and Hitoshi, thanks for the answers guys! I appreciate the attention and the help.

I have a question about the portal-log4j-ext.xml file. Where do I store this file once I have created it?
I could not find the specifics for Glassfish on the Wiki page link that you provided Hitoshi. Is it something that needs to be stored in the server directory or in my portlet project?

Thanks

Ben
Hitoshi Ozawa
RE: Custom logging in LR6.1 disappears after restart
July 9, 2012 2:37 PM
Answer

Hitoshi Ozawa

Rank: Liferay Legend

Posts: 7949

Join Date: March 23, 2010

Recent Posts

As is written in the wiki

Tomcat 6.x: $TOMCAT_HOME/lib/META-INF
Note: As in Tomcat 5.x, you also need to copy log4j.dtd.
Ben Carson
RE: Custom logging in LR6.1 disappears after restart
July 10, 2012 10:07 AM
Answer

Ben Carson

Rank: Junior Member

Posts: 25

Join Date: January 9, 2012

Recent Posts

Hitoshi,
I did see that, thank you. Unfortunately, we are using Glassfish, not Tomcat, and the wiki is pretty unhelpful there:
Other application servers: TBD


Any advice where to store portal-log4j-ext.xml on a Glassfish installation?
I have tried
  • .\bundles\liferay-portal-6.1.0-ce-ga1
  • .\bundles\liferay-portal-6.1.0-ce-ga1\glassfish-3.1.1\lib
  • .\bundles\liferay-portal-6.1.0-ce-ga1\glassfish-3.1.1\domains\domain1\applications\liferay-portal\META-INF

without any success.
I figure I should ask here again instead of continuing to guess.

Thanks again for the help.
David H Nebinger
RE: Custom logging in LR6.1 disappears after restart
July 10, 2012 10:29 AM
Answer

David H Nebinger

Community Moderator

Rank: Liferay Legend

Posts: 11295

Join Date: September 1, 2006

Recent Posts

I'd try .\bundles\liferay-portal-6.1.0-ce-ga1\glassfish-3.1.1\lib\META-INF\portal-log4j-ext.xml...
Ben Carson
RE: Custom logging in LR6.1 disappears after restart
July 10, 2012 12:23 PM
Answer

Ben Carson

Rank: Junior Member

Posts: 25

Join Date: January 9, 2012

Recent Posts

David,
Thanks for the suggestion. Unfortunately, that doesn't work either.
I also tried
  • .\bundles\liferay-portal-6.1.0-ce-ga1\glassfish-3.1.1\domains\domain1\lib\META-INF
  • .\bundles\liferay-portal-6.1.0-ce-ga1\glassfish-3.1.1\domains\domain1\applications\liferay-portal\WEB-INF\lib\META-INF
with no luck.

I am beginning to think that this technique won't work on Glassfish.

Looks like your original suggestion is the way to go. Sorry I didn't try it before, I'm just lazy and was looking for a quick & dirty way to accomplish this. Seems like there should be...
Eric Smith
RE: Custom logging in LR6.1 disappears after restart
March 7, 2013 11:33 AM
Answer

Eric Smith

Rank: Junior Member

Posts: 64

Join Date: August 28, 2012

Recent Posts

Is there any new information on this? I'm using glassfish 3.1.1 (Linux, Liferay 6.1.20) and haven't got it working either. I also couldn't get it working in Liferay Developer Studio with the local Tomcat 7 server.

Local Tomcat 7 in Liferay Developer Studio - Windows 7
I deployed a really simple portlet (Hello You from Liferay In Action book), and added a couple of _log.info(...) lines in various places. These lines always show up in my Liferay Developer Studio console and never show up in my liferay (or tomcat) logs.
I've added the category (com.liferayinaction.portlet.HelloYouPortlet) into Control Panel->Server Administration->Log Levels, tried the startup hook and the portal-log4j-ext.xml.
Note that in all cases I've: restarted the server several times, and have print statements so that I know the hook executed properly without exception. Strangely, for the hook solution the category is missing from the log levels in the web interface (it's present in the other two cases).

Glassfish 3.1.1 - Linux VM
I've tried adding the category in the web interface and adding the startup hook, but neither seem to affect logging. The glassfish log file always contains my log statements even when I set my log level to WARN either manually or using the startup hook (and use INFO in my portlet).
Eric Smith
RE: Custom logging in LR6.1 disappears after restart
March 7, 2013 12:19 PM
Answer

Eric Smith

Rank: Junior Member

Posts: 64

Join Date: August 28, 2012

Recent Posts

To get this compiling and deploying properly I had to deal with a couple of things (using Liferay Developer Studio 1.6.1, creating a Liferay Project: Hook):
- Change import com.liferay.portal.util.PropsUtil;, it should be import com.liferay.portal.kernel.util.PropsUtil;
- Add dom4j.jar to docroot/WEB-INF/lib/ within the project
- I found dom4j.jar in my liferay installation directory
- This was required because I was getting java.lang.ClassNotFoundException: org.dom4j.io.SAXReader