Foren

Custom logging in LR6.1 disappears after restart

thumbnail
Ben Carson, geändert vor 11 Jahren.

Custom logging in LR6.1 disappears after restart

Junior Member Beiträge: 25 Beitrittsdatum: 09.01.12 Neueste Beiträge
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
thumbnail
David H Nebinger, geändert vor 11 Jahren.

RE: Custom logging in LR6.1 disappears after restart

Liferay Legend Beiträge: 14919 Beitrittsdatum: 02.09.06 Neueste Beiträge
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:

package com.example;

import com.liferay.portal.kernel.events.SimpleAction;
import com.liferay.portal.util.PropsUtil;
import com.liferay.util.log4j.Log4JUtil;
import java.util.Properties;
import org.apache.log4j.Level;

public class LoggingStartupAction extends SimpleAction {
    public void run(final String[] ids) {
        // grab any values in the properties file(s) that start with "portal.logging." as these
        // are the guys we want to use for new logging properties.
        Properties props = PropsUtil.getProperties("portal.logging.", true);

        if ((props == null) || (props.isEmpty())) {
            // there are no logging properties defined
            return;
        }

        // If we get here we have at least one logging property to deal with.
        String priority;

        for (String loggerName : props.stringPropertyNames()) {
            // get the priority defined for the logger
            priority = props.getProperty(loggerName, Level.INFO.toString());

            // update the log4j stuff using Liferay's API...
            Log4JUtil.setLevel(loggerName, priority);
        }

        // Done!
    }
}


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

global.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:

portal.logging.com.example=DEBUG
portal.logging.com.example.util=INFO
portal.logging.com.liferay.jdbc=INFO


That should do it!
thumbnail
David H Nebinger, geändert vor 11 Jahren.

RE: Custom logging in LR6.1 disappears after restart

Liferay Legend Beiträge: 14919 Beitrittsdatum: 02.09.06 Neueste Beiträge
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.
Eric Smith, geändert vor 11 Jahren.

RE: Custom logging in LR6.1 disappears after restart

Junior Member Beiträge: 66 Beitrittsdatum: 28.08.12 Neueste Beiträge
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
thumbnail
Juan Gonzalez P, geändert vor 11 Jahren.

RE: Custom logging in LR6.1 disappears after restart

Liferay Legend Beiträge: 3089 Beitrittsdatum: 28.10.08 Neueste Beiträge
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.
thumbnail
Hitoshi Ozawa, geändert vor 11 Jahren.

RE: Custom logging in LR6.1 disappears after restart

Liferay Legend Beiträge: 7942 Beitrittsdatum: 24.03.10 Neueste Beiträge
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.
thumbnail
Ben Carson, geändert vor 11 Jahren.

RE: Custom logging in LR6.1 disappears after restart

Junior Member Beiträge: 25 Beitrittsdatum: 09.01.12 Neueste Beiträge
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
thumbnail
Hitoshi Ozawa, geändert vor 11 Jahren.

RE: Custom logging in LR6.1 disappears after restart

Liferay Legend Beiträge: 7942 Beitrittsdatum: 24.03.10 Neueste Beiträge
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.
thumbnail
Ben Carson, geändert vor 11 Jahren.

RE: Custom logging in LR6.1 disappears after restart

Junior Member Beiträge: 25 Beitrittsdatum: 09.01.12 Neueste Beiträge
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.
thumbnail
David H Nebinger, geändert vor 11 Jahren.

RE: Custom logging in LR6.1 disappears after restart

Liferay Legend Beiträge: 14919 Beitrittsdatum: 02.09.06 Neueste Beiträge
I'd try .\bundles\liferay-portal-6.1.0-ce-ga1\glassfish-3.1.1\lib\META-INF\portal-log4j-ext.xml...
thumbnail
Ben Carson, geändert vor 11 Jahren.

RE: Custom logging in LR6.1 disappears after restart

Junior Member Beiträge: 25 Beitrittsdatum: 09.01.12 Neueste Beiträge
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, geändert vor 11 Jahren.

RE: Custom logging in LR6.1 disappears after restart

Junior Member Beiträge: 66 Beitrittsdatum: 28.08.12 Neueste Beiträge
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).