Foren

Home » Liferay Portal » English » 3. Development

Kombinierte Ansicht Flache Ansicht Baumansicht
Threads [ Zurück | Nächste ]
toggle
michael merker
LiferayLoggerAdapter appears in log output instead of class name
2. April 2013 12:10
Antwort

michael merker

Rang: New Member

Nachrichten: 3

Eintrittsdatum: 2. April 2013

Neue Beiträge

Hi

Environment: liferay-portal-6.1.1-ce-ga2

I'm using slf4j in my portlet. In portal-log4j-ext.xml I made following appender:

1   <appender name="ROOT" class="org.apache.log4j.DailyRollingFileAppender">
2        <param name="File" value="/var/opt/myProject/root.log" />
3        <param name="Append" value="true" />
4        <layout class="org.apache.log4j.PatternLayout">
5            <param name="ConversionPattern" value="%d{dd.MM.yyyy HH:mm:ss,SSS}  %-5p %C{1}:%L %M() - %m%n" />
6        </layout>
7    </appender>


When I check the log output in root.log I see following line:

102.04.2013 15:23:37,022  INFO LiferayLoggerAdapter:114 info() - Try to initialise HTTP client


Instead of seeing my class name where I made the log statement, I see LiferayLoggerAdapter.

Looks like a bug to me or is there something which I configured wrong?
.
TIA
Michael
David H Nebinger
RE: LiferayLoggerAdapter appears in log output instead of class name
2. April 2013 12:20
Antwort

David H Nebinger

Community Moderator

Rang: Liferay Legend

Nachrichten: 11280

Eintrittsdatum: 1. September 2006

Neue Beiträge

From http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/PatternLayout.html:

C: Used to output the fully qualified class name of the caller issuing the logging request.

I think instead you want to use:

c: Used to output the category of the logging event.

LiferayLoggerAdapter is the class issuing the logging request, where your class ('c') is the category being logged (passed in during logger construction, LogFactoryUtil.getLog(c.class)).
michael merker
RE: LiferayLoggerAdapter appears in log output instead of class name
2. April 2013 23:22
Antwort

michael merker

Rang: New Member

Nachrichten: 3

Eintrittsdatum: 2. April 2013

Neue Beiträge

David, thank you for your fast answer. Your solution works for the class name.

But I noticed, that the function name and the line number still showing the data from the LiferayLoggerAdapter. In my example above, function info() and line number 114 are from LiferayLoggerAdapter:

102.04.2013 15:23:37,022  INFO LiferayLoggerAdapter:114 info() - Try to initialise HTTP client


I couldn't find anything here http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/PatternLayout.html which helps for this problem.

Do you have an idea?

Thank you.
Michael
Leonard Broman
RE: LiferayLoggerAdapter appears in log output instead of class name
16. Mai 2013 00:02
Antwort

Leonard Broman

Rang: New Member

Nachrichten: 1

Eintrittsdatum: 15. Mai 2013

Neue Beiträge

This is the effect of how the LiferayLoggerAdapter is built.

If you look at the code you will see that the SLF4J adapter wraps all calls before calling the underlying Liferay logger.

if (isDebugEnabled()) {
FormattingTuple formattingTuple = MessageFormatter.format(
format, argument);

_log.debug(
formattingTuple.getMessage(), formattingTuple.getThrowable());
}

The Log4j liferay logger does in its turn the same thing when calling the Log4J logger.

public void debug(Object msg) {
_logger.log(_FQCN, Level.DEBUG, msg, null);
}

The Log4J Layout counts backward in the stacktrace to find which method is the calling method, but because of the double wrapping it will count wrong.

This breaks the usage of %C, %M, %F and %L (maybe more) in the conversion pattern.

What you would need to do is to somehow isolate the LiferayLoggerAdapter from the classpath of your application to make sure the SLF4J adapter is used instead. Unfortunately it is located in util-java, which is added by the liferay deployer to your webapp when it is deployed. I don't know what side effects you will have if you change this.