+ * Alfresco modules can provide their own log4j.properties file, + * which augments/overrides the global log4j.properties within + * the Alfresco webapp. Within the module's source tree, suppose + * you create:
+ * config/alfresco/module/{module.id}/log4j.properties+ * At deployment time, this log4j.properties file will be placed in:
+ * WEB-INF/classes/alfresco/module/{module.id}/log4j.properties+ * Where {module.id} is whatever value is set within the AMP's + * module.properties file. For details, see: + * Developing an Alfresco Module + *
+ * For example, if {module.id} is "org.alfresco.module.avmCompare", then + * within your source code you'll have:
+ * config/alfresco/module/org.alfresco.module.avmCompare/log4j.properties+ * This would be deployed to:
+ * WEB-INF/classes/alfresco/module/org.alfresco.module.avmCompare/log4j.properties+ * By default the 'overriding_log4j_properties' property of the + * 'log4JHierarchyInit' bean within core-services-context.xml is:
+ * classpath*:alfresco/module/*/log4j.properties+ * Therefore, Log4JHierarchyInit will discover this supplimentary log4j.properties + * file, and merge it with the main log4j.file (WEB-INF/classes/log4j.properties). + * For example, the org.alfresco.module.avmCompare log4j.properties file might look like this: + *
+ * #----------------------------------------------------------------------- + * # webscript module log4j.properties + * # + * # NOTE + * # ---- + * # + * # Log4j uses the following logging levels: + * # debug,info,warn,error,fatal + * # + * # To set the logging level of {fullClassName} to {loglevel}, + * # add a line to this file of the following form: + * # + * # log4j.logger.{fullClassName}={loglevel} + * # + * # For example, to make 'com.example.MyExample' produce 'debug' + * # logs, add a line like this: + * # + * # log4j.logger.com.example.MyExample=debug + * # + * # + * # WARNING + * # ------- + * # Log properties in this log4j.properties file override/augment + * # those in the webapp's main log4j.properties. + * # + * #----------------------------------------------------------------------- + * + * log4j.logger.org.alfresco.module.avmCompare.AvmCompare=info + *+ * + * This system allows the author of any module to provide rich logging control + * without concern for corrupting the central log4j.properties file during + * AMP installation/deinstallation. For details, see: + * Module Management Tool */ public class Log4JHierarchyInit { - private HierarchyDynamicMBean log4jHierarchy; - - public void setLog4jHierarchy(HierarchyDynamicMBean log4jHierarchy) - { - this.log4jHierarchy = log4jHierarchy; - } - - @SuppressWarnings("unchecked") - public void init() - { - // Add each logger (that has a level set) from the Log4J Repository to the Hierarchy MBean - LoggerRepository r = LogManager.getLoggerRepository(); - - Enumeration loggers = r.getCurrentLoggers(); - Logger logger = null; - - while (loggers.hasMoreElements()) - { - logger = (Logger)loggers.nextElement(); - if (logger.getLevel() != null) - { - log4jHierarchy.addLoggerMBean(logger.getName()); - } - } - } + private HierarchyDynamicMBean log4jHierarchy; + private List