RE: Log4j implementation in jsf portlet as seperate file

Ghulam Yaseen Shar, modified 5 Years ago. New Member Posts: 7 Join Date: 9/25/19 Recent Posts
Hello all, In Liferay 6.2 we had a seperate logfile for each portlet inside the tomcat/logs Folder. In Liferay 7.2 ga2 we do not have this anymore, all the logs of all the portlets are written to liferay.log.Is there any approach to also have one logfile per portlet in Liferay 7.2 GA2? We are using JSF portlet not OSGI Modules.
thumbnail
Neil Griffin, modified 5 Years ago. Liferay Legend Posts: 2655 Join Date: 7/27/05 Recent Posts
Hi Ghulam,
Just to clarify, JSF portlets are packaged as WAR artifacts and do not contain any OSGi metadata. However, when you copy a WAR artifact to $LIFERAY_HOME/deploy, the Liferay Web Application Bundle (WAemoticon generator will transform the WAR into a WAB and registersit as a true OSGi module. So even WAR modules are treated by Liferay as OSGi modules after they are deployed.
Are you packaging Log4J inside of WEB-INF/lib? Also, are you packaging log4j.properties? For example:
https://github.com/liferay/liferay-faces-bridge-impl/blob/4.1.3/demo/jsf-applicant-portlet/src/main/resources/log4j.properties

The log4j.properties file typically defines the file appender that lets you log output to a file.
Kind Regards,
Neil
thumbnail
William Gosse, modified 5 Years ago. Liferay Master Posts: 533 Join Date: 7/4/10 Recent Posts
In our LR 7.0 GA1 deployment we found having the the following dependencies allowed us to use Log4j2 in our JSF/Primefaces portlets while Liferay continued to use its Log4j.:        
&nbsp; &nbsp; &nbsp; &nbsp; <dependency>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;<groupid>org.apache.logging.log4j</groupid>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;<artifactid>log4j-core</artifactid>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;<version>2.11.0</version>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;</dependency>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;<dependency>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;<groupid>org.apache.logging.log4j</groupid>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;<artifactid>log4j-slf4j-impl</artifactid>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;<version>2.11.0</version>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;</dependency>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;<dependency>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;<groupid>org.apache.logging.log4j</groupid>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;<artifactid>log4j-1.2-api</artifactid>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;<version>2.11.0</version>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;</dependency>

These dependencies show the use of a combination of Slf4j and log4j 1.2 bridge. With this we could have a separate log4j2.properties in our portlet war file for its own separate logging:
status = error# Directory path where log files are stored
property.basepath = ${sys:catalina.base}/logs/
# Log name
property.logname = aimportletsname = aimportlets_log4J2PropertiesConfig# ConsoleAppender will print logs on console
appender.console.type = Console
appender.console.name = consoleAppender
appender.console.layout.type = PatternLayout
appender.console.layout.pattern=%d{ABSOLUTE} %-5p [%c{1}:%L] %m%n# RollingFileAppender will print logs in file which can be rotated based on time or size
appender.rolling.type = RollingFile
appender.rolling.name = fileAppender
appender.rolling.fileName=${basepath}${logname}.log
appender.rolling.filePattern=${basepath}${logname}_%d{yyyyMMdd}.log.gz
appender.rolling.append = true
appender.rolling.layout.type = PatternLayout
appender.rolling.layout.pattern = %d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
appender.rolling.policies.type = Policies
# Rotate log file each day
appender.rolling.policies.time.type = TimeBasedTriggeringPolicy
appender.rolling.policies.time.interval = 1
appender.rolling.policies.time.modulate = true
appender.rolling.strategy.type = DefaultRolloverStrategy
appender.rolling.strategy.delete.type = Delete
appender.rolling.strategy.delete.basePath = ${basepath}
appender.rolling.strategy.delete.maxDepth = 1
appender.rolling.strategy.delete.ifLastModified.type = IfLastModified
# Delete files older than 30 days
appender.rolling.strategy.delete.ifLastModified.age = 30d# Configure root logger
rootLogger.level = info
rootLogger.appenderRef.stdout.ref = consoleAppender
rootLogger.appenderRef.fileio.ref = fileAppender


This allowed us to specify a log file that was specific to the portlets in our war file and also allowed messages to go the tomcat catalina.out file as well. Hope this helps.