Foren

LiferayLoggerAdapter appears in log output instead of class name

michael merker, geändert vor 10 Jahren.

LiferayLoggerAdapter appears in log output instead of class name

New Member Beiträge: 3 Beitrittsdatum: 02.04.13 Neueste 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:

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


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

02.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
thumbnail
David H Nebinger, geändert vor 10 Jahren.

RE: LiferayLoggerAdapter appears in log output instead of class name

Liferay Legend Beiträge: 14913 Beitrittsdatum: 02.09.06 Neueste 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, geändert vor 10 Jahren.

RE: LiferayLoggerAdapter appears in log output instead of class name

New Member Beiträge: 3 Beitrittsdatum: 02.04.13 Neueste 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:

02.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, geändert vor 10 Jahren.

RE: LiferayLoggerAdapter appears in log output instead of class name (Antwort)

New Member Beitrag: 1 Beitrittsdatum: 16.05.13 Neueste 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.