1) Maven Dependencies:
We do a lot of logging, and have a lot of libraries that bring their own
requirements, so this is what we have:
In the <properties> stanza:
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<jdk.version>1.8</jdk.version>
<struts.version>2.5.13</struts.version>
<tiles.version>3.0.7</tiles.version>
<spring.version>4.1.0.RELEASE</spring.version>
<org.springframework.version>4.1.0.RELEASE</org.springframework.version>
<hibernate.version>5.1.0.Final</hibernate.version>
<log4j2.version>2.6.2</log4j2.version>
<jboss.logging.version>3.2.0.Final</jboss.logging.version>
<jersey.version>2.22.4</jersey.version>
<slf.version>1.7.12</slf.version>
</properties>
in the dependencies:
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>${log4j2.version}</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>${log4j2.version}</version>
</dependency>
<!-- This is required for freemarker -->
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-1.2-api</artifactId>
<version>${log4j2.version}</version>
</dependency>
<!-- In case you use SLF4J -->
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
<version>${log4j2.version}</version>
</dependency>
<dependency>
<groupId>org.jboss.logging</groupId>
<artifactId>jboss-logging</artifactId>
<version>${jboss.logging.version}</version>
</dependency>
2) log4j2.xml (not a properties file at this time...)
Put your contextRoot as the log-name
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="ERROR">
<Properties>
<Property name="log-name">BusinessPortal</Property>
<Property name="log-home">${sys:LOG_HOME}</Property>
<Property name="log-level">${sys:LOG_LEVEL}</Property>
<Property name="log-size">${sys:LOG_MAXFILESIZE}</Property>
<Property name="log-maxFiles">${sys:LOG_MAXBACKUPINDEX}</Property>
</Properties>
<Appenders>
<RollingFile name="RollingFile"
fileName="${log-home}/${log-name}.log"
filePattern="${log-home}/${log-name}-%d{yyyy-MM-dd}-%i.log" >
<PatternLayout>
<pattern>%d{MM/dd/yyyy HH:mm:ss,SSS}- %c{10}: %m%n</pattern>
</PatternLayout>
<Policies>
<SizeBasedTriggeringPolicy size="${log-size}" />
</Policies>
<DefaultRolloverStrategy>
<Delete basePath="${log-home}" maxDepth="2">
<IfFileName glob="${log-name}*"/>
<IfAccumulatedFileCount exceeds="${log-maxFiles}"/>
</Delete>
</DefaultRolloverStrategy>
</RollingFile>
</Appenders>
<Loggers>
<Logger name="root" level="${log-level}" additivity="false">
<appender-ref ref="RollingFile" level="${log-level}"/>
</Logger>
<Logger name="com.opensymphony.xwork2" level="ERROR" additivity="false">
<appender-ref ref="RollingFile" level="ERROR"/>
</Logger>
<Logger name="org.hibernate" level="ERROR" additivity="false">
<appender-ref ref="RollingFile" level="ERROR"/>
</Logger>
<Logger name="org.springframework" level="ERROR" additivity="false">
<appender-ref ref="RollingFile" level="ERROR"/>
</Logger>
<Logger name="freemarker" level="ERROR" additivity="false">
<appender-ref ref="RollingFile" level="ERROR"/>
</Logger>
<Logger name="org.apache.commons" level="ERROR" additivity="false">
<appender-ref ref="RollingFile" level="ERROR"/>
</Logger>
<Logger name="org.apache.struts2" level="WARN" additivity="false">
<appender-ref ref="RollingFile" level="WARN"/>
</Logger>
<Logger name="org.apache.tiles" level="WARN" additivity="false">
<appender-ref ref="RollingFile" level="WARN"/>
</Logger>
<Root level="debug" additivity="false">
<AppenderRef ref="RollingFile"/>
</Root>
</Loggers>
</Configuration>
3) In our server, we set environment variables used by the log4j2.xml, so
the environments (dev/beta/prod) can have different setup:
For weblogic, a setUserOverrides.cmd:
set JAVA_OPTIONS=%JAVA_OPTIONS%
-DLOG_HOME=/u01/projects/app-logs
-DLOG_LEVEL=DEBUG
-DLOG_MAXFILESIZE=500KB
-DLOG_MAXBACKUPINDEX=5
-DCOMMON_HOME=/u01/projects/common
for WildFly, add properties in standalone.xml - this from my laptop
development environment:
<system-properties>
<property name="SERVER_ENV_TYPE" value="LOCAL_DEV"/>
<property name="LOG_LEVEL" value="DEBUG"/>
<property name="LOG_MAXFILESIZE" value="500MB"/>
<property name="LOG_MAXBACKUPINDEX" value="5"/>
<property name="LOG_HOME" value="C:/srv/websites/app-logs"/>
<property name="COMMON_HOME" value="C:/srv/websites/common"/>
</system-properties>
Hope that helps!
Louis
On Tue, Oct 24, 2017 at 6:47 AM, [email protected] <
[email protected]> wrote:
> Hello,
>
> I have migrated my project from struts 2.3 to struts 2.5 .
> I am facing a problem while upgrading to log4j2 from log4j1
> I need help to configure the log4j2 with my system
>
> My questions are.
>
> 1. What jars I need to add to my system for log4j2
> 2. How to write the log4j.properties files for log4j2
>
> Thanks
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>
>