Search code examples
javatomcatloggingliferayportlet

Logger in Liferay is not working


I'm using Liferay 6.20 with a tomcat.

According to this post: Liferay: what is the default approach for logging in Liferay? I've added a logger to my basic portlet class like this:

package mypackage.katalog;

import java.io.IOException;

import javax.portlet.ActionRequest;
import javax.portlet.ActionResponse;
import javax.portlet.PortletException;

import com.liferay.portal.kernel.log.Log;
import com.liferay.portal.kernel.log.LogFactoryUtil;
import com.liferay.util.bridges.mvc.MVCPortlet;

/**
 * Portlet implementation class KatalogUslugPortlet
 */
public class KatalogUslugPortlet extends MVCPortlet {
    private static Log _log = LogFactoryUtil.getLog(KatalogUslugPortlet.class);

    @Override
    public void processAction(ActionRequest actionRequest,
            ActionResponse actionResponse) throws IOException, PortletException {

        testLogger();

        super.processAction(actionRequest, actionResponse);
    }

    private void testLogger() {
        System.out.print("SYSTEM_OUT!!!");

        _log.info("INFO!!!");
        _log.debug("DEBUG!!!");
        _log.error("ERROR!!!");
    }
}

And logs are not appearing neither in the console, nor in the tomcat logs. What could gone wrong?


Solution

  • The problem was not in the logger. My portlet was just drag and dropped into my site and I thought that processAction(...) was the method that was called after each site refresh. In fact it should have look use doView(...) method as follows:

    @Override
    public void doView(RenderRequest renderRequest,
            RenderResponse renderResponse) throws IOException, PortletException {
    
        testLogger();
    
        super.doView(renderRequest, renderResponse);
    }