Commit 3031b401 authored by Martin Bergljung's avatar Martin Bergljung
Browse files

Fix logging for Share extensions, #418

parent 723b3096
Loading
Loading
Loading
Loading
+54 −0
Original line number Diff line number Diff line
# Set root logger level to error
log4j.rootLogger=error, Console, File

###### Console appender definition #######

# All outputs currently set to be a ConsoleAppender.
log4j.appender.Console=org.apache.log4j.ConsoleAppender
log4j.appender.Console.layout=org.apache.log4j.PatternLayout

# use log4j NDC to replace %x with tenant domain / username
log4j.appender.Console.layout.ConversionPattern=%d{ISO8601} %x %-5p [%c{3}] [%t] %m%n
#log4j.appender.Console.layout.ConversionPattern=%d{ABSOLUTE} %-5p [%c] %m%n

###### File appender definition #######
log4j.appender.File=org.apache.log4j.DailyRollingFileAppender
log4j.appender.File.File=share.log
log4j.appender.File.Append=true
log4j.appender.File.DatePattern='.'yyyy-MM-dd
log4j.appender.File.layout=org.apache.log4j.PatternLayout
log4j.appender.File.layout.ConversionPattern=%d{yyyy-MM-dd} %d{ABSOLUTE} %-5p [%c] [%t] %m%n

# Spring
log4j.logger.org.springframework=warn
# Turn off Spring remoting warnings that should really be info or debug.
log4j.logger.org.springframework.remoting.support=error
log4j.logger.org.springframework.util=error

# MyFaces
log4j.logger.org.apache.myfaces.util.DebugUtils=info
log4j.logger.org.apache.myfaces.el.VariableResolverImpl=error
log4j.logger.org.apache.myfaces.application.jsp.JspViewHandlerImpl=error
log4j.logger.org.apache.myfaces.taglib=error

# Alfresco
log4j.logger.org.alfresco=error
log4j.logger.org.alfresco.config=warn
log4j.logger.org.alfresco.config.JndiObjectFactoryBean=warn
log4j.logger.org.alfresco.web=info

# Web Framework
log4j.logger.org.springframework.extensions.webscripts=info
log4j.logger.org.springframework.extensions.webscripts.ScriptLogger=warn
log4j.logger.org.springframework.extensions.webscripts.ScriptDebugger=off

# Freemarker
# Note the freemarker.runtime logger is used to log non-fatal errors that are handled by Alfresco's retrying transaction handler
log4j.logger.freemarker.runtime=

#-----------------------------------------------------------------------
# Custom Share module logging goes here...
#-----------------------------------------------------------------------


+54 −0
Original line number Diff line number Diff line
# Set root logger level to error
log4j.rootLogger=error, Console, File

###### Console appender definition #######

# All outputs currently set to be a ConsoleAppender.
log4j.appender.Console=org.apache.log4j.ConsoleAppender
log4j.appender.Console.layout=org.apache.log4j.PatternLayout

# use log4j NDC to replace %x with tenant domain / username
log4j.appender.Console.layout.ConversionPattern=%d{ISO8601} %x %-5p [%c{3}] [%t] %m%n
#log4j.appender.Console.layout.ConversionPattern=%d{ABSOLUTE} %-5p [%c] %m%n

###### File appender definition #######
log4j.appender.File=org.apache.log4j.DailyRollingFileAppender
log4j.appender.File.File=share.log
log4j.appender.File.Append=true
log4j.appender.File.DatePattern='.'yyyy-MM-dd
log4j.appender.File.layout=org.apache.log4j.PatternLayout
log4j.appender.File.layout.ConversionPattern=%d{yyyy-MM-dd} %d{ABSOLUTE} %-5p [%c] [%t] %m%n

# Spring
log4j.logger.org.springframework=warn
# Turn off Spring remoting warnings that should really be info or debug.
log4j.logger.org.springframework.remoting.support=error
log4j.logger.org.springframework.util=error

# MyFaces
log4j.logger.org.apache.myfaces.util.DebugUtils=info
log4j.logger.org.apache.myfaces.el.VariableResolverImpl=error
log4j.logger.org.apache.myfaces.application.jsp.JspViewHandlerImpl=error
log4j.logger.org.apache.myfaces.taglib=error

# Alfresco
log4j.logger.org.alfresco=error
log4j.logger.org.alfresco.config=warn
log4j.logger.org.alfresco.config.JndiObjectFactoryBean=warn
log4j.logger.org.alfresco.web=info

# Web Framework
log4j.logger.org.springframework.extensions.webscripts=info
log4j.logger.org.springframework.extensions.webscripts.ScriptLogger=warn
log4j.logger.org.springframework.extensions.webscripts.ScriptDebugger=off

# Freemarker
# Note the freemarker.runtime logger is used to log non-fatal errors that are handled by Alfresco's retrying transaction handler
log4j.logger.freemarker.runtime=

#-----------------------------------------------------------------------
# Custom Share module logging goes here...
#-----------------------------------------------------------------------


+55 −1
Original line number Diff line number Diff line
@@ -159,6 +159,17 @@ public class RunMojo extends AbstractMojo {
    @Parameter(property = "maven.alfresco.shareContextPath", defaultValue = "/share")
    protected String shareContextPath;

    /**
     * Share Log4j.properties configuration cannot be customized via extension
     * put on the classpath, like on the platform side.
     * So we need to override the log4j.properties in share/WEB-INF/classes
     * to be able to log from custom code.
     * This property can be used to turn off this overriding, to produce a WAR with
     * the standard Share log4j.properties file.
     */
    @Parameter(property = "maven.alfresco.useCustomShareLog4jConfig", defaultValue = "true")
    protected boolean useCustomShareLog4jConfig;

    /**
     * Switch to enable/disable the Alfresco REST API Explorer (api-explorer.war) when running embedded Tomcat.
     */
@@ -645,7 +656,7 @@ public class RunMojo extends AbstractMojo {
    }

    /**
     * Copy the Activiti Log4J Dev config into the activiti-app/WEB-INF/classes dir.
     * Copy the Activiti Log4J Dev config into the activitiApp-war/WEB-INF/classes dir.
     *
     * @throws MojoExecutionException
     */
@@ -678,6 +689,47 @@ public class RunMojo extends AbstractMojo {
        );
    }

    /**
     * Copy a custom Share Log4J config into the share-war/WEB-INF/classes dir.
     * There is no custom classpath resolve mechanism for Share log4j,
     * to log custom stuff overriding standard log4j.properties is needed.
     *
     * @throws MojoExecutionException
     */
    protected void copyShareLog4jConfig() throws MojoExecutionException {
        if (!useCustomShareLog4jConfig) {
            getLog().info("NOT overriding share/WEB-INF/classes/log4j.properties");
            return;
        }

        final String warOutputDir = getWarOutputDir(SHARE_WAR_PREFIX_NAME);
        final String logConfDestDir = warOutputDir + "/WEB-INF/classes";

        getLog().info("Copying Share log4j.properties to: " + logConfDestDir);

        executeMojo(
                plugin(
                        groupId("org.apache.maven.plugins"),
                        artifactId("maven-resources-plugin"),
                        version(MAVEN_RESOURCE_PLUGIN_VERSION)
                ),
                goal("copy-resources"),
                configuration(
                        element(name("outputDirectory"), logConfDestDir),
                        element(name("resources"),
                                element(name("resource"),
                                        element(name("directory"), "src/test/resources/share"),
                                        element(name("includes"),
                                                element(name("include"), "log4j.properties")
                                        ),
                                        element(name("filtering"), "true")
                                )
                        )
                ),
                execEnv
        );
    }

    /**
     * Build the customized Platform webapp (i.e. the Repository, alfresco.war)
     * that should be deployed by Tomcat by applying all AMPs and JARs from
@@ -707,6 +759,8 @@ public class RunMojo extends AbstractMojo {
        buildCustomWarInDir(SHARE_WAR_PREFIX_NAME, shareModules,
                alfrescoGroupId, alfrescoShareWarArtifactId, alfrescoShareVersion);

        copyShareLog4jConfig();

        String shareWarArtifactId = packageAndInstallCustomWar(SHARE_WAR_PREFIX_NAME);

        // Set up the custom share war to be run by Tomcat plugin