Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Michel Wicky
i'm not able set my log file
May 14, 2011 1:08 PM
Answer

Michel Wicky

Rank: Regular Member

Posts: 130

Join Date: July 2, 2010

Recent Posts

I'm encountering very serious problem with classes generated with services builder and would like to debug my portlet to better understand what/where the problem is.

Is setted a log file in log4j.properties in ..\ROOT\WEB-INF\classes

log4j.rootCategory=DEBUG, CONSOLE

log4j.appender.CONSOLE=org.apache.log4j.FileAppender
log4j.appender.CONSOLE.File=C:/liferay-portal-6.0.6/tomcat-6.0.29/logs/liferay.log
log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
log4j.appender.CONSOLE.layout.ConversionPattern=%d{ABSOLUTE} %-5p [%c{1}:%L] %m%n

I setted level to DEBUG for hibernate into portal-log4j-ext.xml in ..\ROOT\WEB-INF\classes\META-INF

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">

<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
<category name="org.hibernate">
<priority value="DEBUG" />
</category>
</log4j:configuration>

After restarting the server, i got a liferay.log file but with only some DEBUG into not related to hibernate ... at the console however i can see a lot of new entry ... what i'm doing wrong ! both setting seem providing some result but why in the hell what i see on the console is not in my log file ?

Second question, i would like to debug my portlet and not all server activity ... is it a way to define the log level only for hibernate for what is executed by the portlet ?

Any help would be appreciate as it is to solve what i think is a bug in generated service builder classes !
Adolfo Benedetti
RE: i'm not able set my log file
May 14, 2011 2:10 PM
Answer

Adolfo Benedetti

Rank: Junior Member

Posts: 45

Join Date: June 3, 2009

Recent Posts

You can use the liferay log, like in this hook example;
 1....
 2import com.liferay.portal.kernel.log.Log;
 3import com.liferay.portal.kernel.log.LogFactoryUtil;
 4.....
 5public class MyListener extends BaseModelListener<Group> {
 6private static Log _log = LogFactoryUtil.getLog(MyListener.class);
 7......
 8  @Override
 9  public void onAfterCreate(Group group) throws ModelListenerException {
10    _log.info(......);
11.......

This works on liferay 6.0.5
Michel Wicky
RE: i'm not able set my log file
May 14, 2011 2:14 PM
Answer

Michel Wicky

Rank: Regular Member

Posts: 130

Join Date: July 2, 2010

Recent Posts

Thank you Andolfo, that's not the question but it is helpful because it is an information for the next step in my development.
I would like to debug org.hibernate and i'm able to but only on the console. I'm not able to configure this entry to be appended in the log file. That's my current problem.
Jelmer Kuperus
RE: i'm not able set my log file
May 14, 2011 4:38 PM
Answer

Jelmer Kuperus

Rank: Liferay Legend

Posts: 1192

Join Date: March 10, 2010

Recent Posts

Try removing the entries you made in log4j.properties
and instead add the following entries to your portal-log4j-ext.xml


1    <appender name="FILE" class="org.apache.log4j.RollingFileAppender">
2        <param name="File" value="${catalina.base}/logs/liferay.log" />
3        <param name="Append" value="true"/>
4        <layout class="org.apache.log4j.PatternLayout">
5        <param name="ConversionPattern" value="%d %p [%c] - %m%n"/>
6        </layout>
7    </appender>


1    <root>
2        <appender-ref ref="FILE"/>
3    </root>
Michel Wicky
RE: i'm not able set my log file
May 15, 2011 11:28 PM
Answer

Michel Wicky

Rank: Regular Member

Posts: 130

Join Date: July 2, 2010

Recent Posts

I got some warning when setting the parameters as you mentionned.

log4j:WARN Continuable parsing error 6 and column 13
log4j:WARN The content of element type "root" must match "(param*,(priority|level)?,appender-ref*)".
log4j:WARN Continuable parsing error 12 and column 19
log4j:WARN The content of element type "layout" must match "(param)*".
log4j:WARN Continuable parsing error 13 and column 17
log4j:WARN The content of element type "appender" must match "(errorHandler?,param*,rollingPolicy?,triggeringPolicy?,connectionSource?,layout?,filter*,appender-ref*)".
log4j:WARN Continuable parsing error 17 and column 23
log4j:WARN The content of element type "log4j:configuration" must match "(renderer*,appender*,plugin*,(category|logger)*,root?,(categoryFactory|loggerFactory)?)".
Starting Liferay Portal Community Edition 6.0.6 CE (Bunyan / Build 6006 / February 17, 2011)

Here is my file:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
<root>
2 <appender-ref ref="FILE"/>
3 </root>
<appender name="FILE" class="org.apache.log4j.RollingFileAppender">
2 <param name="File" value="${catalina.base}/logs/liferay.log"/>
3 <param name="Append" value="true"/>
4 <layout class="org.apache.log4j.PatternLayout">
5 <param name="ConversionPattern" value="%d %p [%c] - %m%n"/>
6 </layout>
7 </appender>
<category name="org.hibernate">
<priority value="DEBUG"/>
</category>
</log4j:configuration>
Yan Naing Oo
RE: i'm not able set my log file
June 14, 2011 9:07 PM
Answer

Yan Naing Oo

Rank: Regular Member

Posts: 180

Join Date: February 17, 2011

Recent Posts

jelmer kuperus:
Try removing the entries you made in log4j.properties
and instead add the following entries to your portal-log4j-ext.xml


1    <appender name="FILE" class="org.apache.log4j.RollingFileAppender">
2        <param name="File" value="${catalina.base}/logs/liferay.log" />
3        <param name="Append" value="true"/>
4        <layout class="org.apache.log4j.PatternLayout">
5        <param name="ConversionPattern" value="%d %p [%c] - %m%n"/>
6        </layout>
7    </appender>


1    <root>
2        <appender-ref ref="FILE"/>
3    </root>





I m using 6.0.6 the portal-log4j-ext.xml place it in webapps\ROOT\WEB-INF\classes. then no logs is see
any suggestion ?
Yan Naing Oo
RE: i'm not able set my log file
August 29, 2012 12:52 AM
Answer

Yan Naing Oo

Rank: Regular Member

Posts: 180

Join Date: February 17, 2011

Recent Posts

Hello,

I have figured out the logs file out issues. below is the step to follow

1. create portal-log4j-ext.xml
2. create META-INF under ROOT\WEB-INF\classes\ .. then place it the portal-log4-ext file

Inside code below

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
<root>
<appender-ref ref="FILE"/>
</root>

<appender name="FILE" class="org.apache.log4j.RollingFileAppender">
<param name="File" value="${catalina.base}/logs/liferay.log"/>
<param name="Append" value="true"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d %p [%c] - %m%n"/>
</layout>
</appender>

<category name="org.hibernate">
<priority value="ERROR"/>
<priority value="WARN"/>
</category>
</log4j:configuration>


then it will write out in liferay.log file whenever get the error or warning etc..
David H Nebinger
RE: i'm not able set my log file
August 29, 2012 7:15 AM
Answer

David H Nebinger

Rank: Liferay Legend

Posts: 7220

Join Date: September 1, 2006

Recent Posts

Michel Wicky:
I'm encountering very serious problem with classes generated with services builder and would like to debug my portlet to better understand what/where the problem is.


Your problem is that you assume you can do your own logging implementation for service builder entities, which is incorrect.

You should be using the Liferay logging API as another user has suggested. You should add your logging to the portal-ext-log4j.xml in ROOT's WEB-INF/classes.

If you try using your own log4j instance, you'll end up w/ class loader issues since the log4j instance is actually ROOT's and not your own, and therefore it will not be able to load your log4j.xml file as a result.

We don't like using Liferay's logging api (we prefer that our individual portlets have their own logging files so we don't have to weed through Liferay's logs and filter stuff out). So for our service providing plugin, that one (and only that one) leverages the Liferay logging API. The rest of the portlets (since their not tightly coupled w/ the lower level integration stuff that a service builder entity is) uses their own log4j logging pretty much w/o any issue.