Custom Log4j2 Definition in ACS 7.4+

cancel
Showing results for 
Search instead for 
Did you mean: 
robinp
Partner

Custom Log4j2 Definition in ACS 7.4+

Jump to solution

Hi all,

I'm going crazy over a trivial configuration of log4j2 on alfresco 7.4+

Have any of you ever had problems declaring new custom loggers for new module packages using the standard Docker Deployment with SDK 4.8 for ACS?

I followed this guide https://docs.alfresco.com/content-services/latest/upgrade/log4j2-migrate/ but it seems that it doesn't take my custom configuration in any case. I tried editing custom-log4j2.properties defined under src/main/resources/alfresco/module/mymodule/ and also dev-log4j2.properties defined in the platform docker project.

My custom logger definitions follow exactly the structure of the guide I linked before from the alfresco documentation. Thanks in advance

1 Solution

Accepted Solutions
luca_biondo
Active Member II

Re: Custom Log4j2 Definition in ACS 7.4+

Jump to solution

Hi all,

after lots of tests we found out the solution, following the [MNT-24306] Added fix for log4j2 config issue.

In order to get the logs inside the docker environment created by the run.sh build_start command you need to:

1) Edit the following 2 files:

1.1) Dockerfile inside the <my-project>-platform-docker module

FROM ${docker.acs.image}:${alfresco.platform.version}

ARG TOMCAT_DIR=/usr/local/tomcat
ARG USERNAME=${alfresco.platform.docker.user} 

USER root

# Copy Dockerfile to avoid an error if no JARs exist
COPY Dockerfile extensions/*.jar $TOMCAT_DIR/webapps/alfresco/WEB-INF/lib/

# Copy Dockerfile to avoid an error if no AMPs exist
COPY Dockerfile extensions/*.amp $TOMCAT_DIR/amps/
RUN java -jar $TOMCAT_DIR/alfresco-mmt/alfresco-mmt*.jar install \
              $TOMCAT_DIR/amps $TOMCAT_DIR/webapps/alfresco -directory -nobackup -force

COPY alfresco-global.properties $TOMCAT_DIR/shared/classes/alfresco-global.properties
COPY dev-log4j2.properties $TOMCAT_DIR/shared/classes/alfresco/extension/dev-log4j2.properties
COPY disable-webscript-caching-context.xml $TOMCAT_DIR/shared/classes/alfresco/extension

# Copy Dockerfile to avoid an error if no license file exists
COPY Dockerfile license/*.* $TOMCAT_DIR/webapps/alfresco/WEB-INF/classes/alfresco/extension/license/

# Move the log file
RUN sed -i -e "s_appender.rolling.fileName\=alfresco.log_appender.rolling.fileName\=${TOMCAT_DIR}/logs\/alfresco.log_" \
        ${TOMCAT_DIR}/shared/classes/alfresco/extension/dev-log4j2.properties && \
    sed -i -e "s_appender.rolling.filePattern=alfresco.log.%d{yyyy-MM-dd}_appender.rolling.filePattern\=${TOMCAT_DIR}/logs\/alfresco.log.%d{yyyy-MM-dd}_" \
        ${TOMCAT_DIR}/shared/classes/alfresco/extension/dev-log4j2.properties

USER ${USERNAME}

1.2) dev-log4j2.properties inside the <my-project>-platform-docker module

 

rootLogger.level=error
rootLogger.appenderRef.stdout.ref=ConsoleAppender
rootLogger.appenderRef.rolling.ref=RollingAppender

.....

 

.....

# Authorization logger.alfresco-enterprise-repo-authorization-AuthorizationService.name=org.alfresco.enterprise.repo.authorization.AuthorizationService logger.alfresco-enterprise-repo-authorization-AuthorizationService.level=info logger.alfresco-enterprise-repo-authorization-AuthorizationsConsistencyMonitor.name=org.alfresco.enterprise.repo.authorization.AuthorizationsConsistencyMonitor logger.alfresco-enterprise-repo-authorization-AuthorizationsConsistencyMonitor.level=warn

 

From line 1 to line 402 of this link:

https://github.com/Alfresco/alfresco-sdk/blob/c0054d34a1b140cd175d89e8873ab16c54cef9fd/archetypes/al... 

2) Add your package configuration at the end of the dev-log4j2.properties

 

logger.my-name.name=my.package
logger.my-name.level=debug
 
With this configuration it works in your local docker environment
 
Alternatively you can use the log4j2.properties file located in <myproject>-platform/src/main/resources/alfresco/module/<my-module> with the same configuration above.
 
CARE: this configuration will OVERRIDE the dev-log4j2.properties
 
3) Inside your class you can now log with
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

//inside your class private static final Logger logger = LoggerFactory.getLogger(MyClass.class);
//inside your method logger.debug("Test debug logging. Congratulation your JAR Module is working"); logger.info("This is only for information purposes. Better remove me from the log in Production");
CARE: do not use org.apache.commons.logging as for us it didn't work (even if is the method used inside the DemoComponent of the SDK)
 
Thank you
Luca & Robin
 

 

 

View solution in original post

3 Replies
angelborroy
Alfresco Employee

Re: Custom Log4j2 Definition in ACS 7.4+

Jump to solution

It looks like there is a problem with the SDK.

This PR seems to fix the issue: https://github.com/Alfresco/alfresco-sdk/pull/664

Hyland Developer Evangelist
luca_biondo
Active Member II

Re: Custom Log4j2 Definition in ACS 7.4+

Jump to solution

Hi all,

after lots of tests we found out the solution, following the [MNT-24306] Added fix for log4j2 config issue.

In order to get the logs inside the docker environment created by the run.sh build_start command you need to:

1) Edit the following 2 files:

1.1) Dockerfile inside the <my-project>-platform-docker module

FROM ${docker.acs.image}:${alfresco.platform.version}

ARG TOMCAT_DIR=/usr/local/tomcat
ARG USERNAME=${alfresco.platform.docker.user} 

USER root

# Copy Dockerfile to avoid an error if no JARs exist
COPY Dockerfile extensions/*.jar $TOMCAT_DIR/webapps/alfresco/WEB-INF/lib/

# Copy Dockerfile to avoid an error if no AMPs exist
COPY Dockerfile extensions/*.amp $TOMCAT_DIR/amps/
RUN java -jar $TOMCAT_DIR/alfresco-mmt/alfresco-mmt*.jar install \
              $TOMCAT_DIR/amps $TOMCAT_DIR/webapps/alfresco -directory -nobackup -force

COPY alfresco-global.properties $TOMCAT_DIR/shared/classes/alfresco-global.properties
COPY dev-log4j2.properties $TOMCAT_DIR/shared/classes/alfresco/extension/dev-log4j2.properties
COPY disable-webscript-caching-context.xml $TOMCAT_DIR/shared/classes/alfresco/extension

# Copy Dockerfile to avoid an error if no license file exists
COPY Dockerfile license/*.* $TOMCAT_DIR/webapps/alfresco/WEB-INF/classes/alfresco/extension/license/

# Move the log file
RUN sed -i -e "s_appender.rolling.fileName\=alfresco.log_appender.rolling.fileName\=${TOMCAT_DIR}/logs\/alfresco.log_" \
        ${TOMCAT_DIR}/shared/classes/alfresco/extension/dev-log4j2.properties && \
    sed -i -e "s_appender.rolling.filePattern=alfresco.log.%d{yyyy-MM-dd}_appender.rolling.filePattern\=${TOMCAT_DIR}/logs\/alfresco.log.%d{yyyy-MM-dd}_" \
        ${TOMCAT_DIR}/shared/classes/alfresco/extension/dev-log4j2.properties

USER ${USERNAME}

1.2) dev-log4j2.properties inside the <my-project>-platform-docker module

 

rootLogger.level=error
rootLogger.appenderRef.stdout.ref=ConsoleAppender
rootLogger.appenderRef.rolling.ref=RollingAppender

.....

 

.....

# Authorization logger.alfresco-enterprise-repo-authorization-AuthorizationService.name=org.alfresco.enterprise.repo.authorization.AuthorizationService logger.alfresco-enterprise-repo-authorization-AuthorizationService.level=info logger.alfresco-enterprise-repo-authorization-AuthorizationsConsistencyMonitor.name=org.alfresco.enterprise.repo.authorization.AuthorizationsConsistencyMonitor logger.alfresco-enterprise-repo-authorization-AuthorizationsConsistencyMonitor.level=warn

 

From line 1 to line 402 of this link:

https://github.com/Alfresco/alfresco-sdk/blob/c0054d34a1b140cd175d89e8873ab16c54cef9fd/archetypes/al... 

2) Add your package configuration at the end of the dev-log4j2.properties

 

logger.my-name.name=my.package
logger.my-name.level=debug
 
With this configuration it works in your local docker environment
 
Alternatively you can use the log4j2.properties file located in <myproject>-platform/src/main/resources/alfresco/module/<my-module> with the same configuration above.
 
CARE: this configuration will OVERRIDE the dev-log4j2.properties
 
3) Inside your class you can now log with
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

//inside your class private static final Logger logger = LoggerFactory.getLogger(MyClass.class);
//inside your method logger.debug("Test debug logging. Congratulation your JAR Module is working"); logger.info("This is only for information purposes. Better remove me from the log in Production");
CARE: do not use org.apache.commons.logging as for us it didn't work (even if is the method used inside the DemoComponent of the SDK)
 
Thank you
Luca & Robin
 

 

 

lucastancapiano
Partner

Re: Custom Log4j2 Definition in ACS 7.4+

Jump to solution

great!