Ask Questions and Find Answers
Important:
Ask is now read-only. You can review any existing questions and answers, but not add anything new.
But - don't panic! While ask is no more, we've replaced it with discuss - the new Liferay Discussion Forum! Read more here here or just visit the site here:
discuss.liferay.com
RE: Log4j implementation in jsf portlet as seperate file
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.
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 (WA
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
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 (WA

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
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.:
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:
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.
<dependency>
<groupid>org.apache.logging.log4j</groupid>
<artifactid>log4j-core</artifactid>
<version>2.11.0</version>
</dependency>
<dependency>
<groupid>org.apache.logging.log4j</groupid>
<artifactid>log4j-slf4j-impl</artifactid>
<version>2.11.0</version>
</dependency>
<dependency>
<groupid>org.apache.logging.log4j</groupid>
<artifactid>log4j-1.2-api</artifactid>
<version>2.11.0</version>
</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.
Copyright © 2025 Liferay, Inc
• Privacy Policy
Powered by Liferay™