dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #36962
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 18908: Log. Logging of aync processes including analytics tables, resource tables and data synchronizati...
------------------------------------------------------------
revno: 18908
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2015-04-15 16:58:13 +0200
message:
Log. Logging of aync processes including analytics tables, resource tables and data synchronization is now outputted to separate files under /home/larshelg/dev/config/dhis2/logs/*.log. This will make it easier to monitor async processes with less noise from standard logging. File size is limited to 25MB plus 3 backup files for now.
added:
dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/log/
dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/log/Log4JLogConfigInitializer.java
dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/log/LogConfigInitializer.java
modified:
dhis-2/dhis-support/dhis-support-system/pom.xml
dhis-2/dhis-support/dhis-support-system/src/main/resources/META-INF/dhis/beans.xml
--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk
Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-support/dhis-support-system/pom.xml'
--- dhis-2/dhis-support/dhis-support-system/pom.xml 2015-03-31 12:36:25 +0000
+++ dhis-2/dhis-support/dhis-support-system/pom.xml 2015-04-15 14:58:13 +0000
@@ -23,6 +23,10 @@
</dependency>
<dependency>
<groupId>org.hisp.dhis</groupId>
+ <artifactId>dhis-support-external</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.hisp.dhis</groupId>
<artifactId>dhis-support-hibernate</artifactId>
</dependency>
<dependency>
=== added directory 'dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/log'
=== added file 'dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/log/Log4JLogConfigInitializer.java'
--- dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/log/Log4JLogConfigInitializer.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/log/Log4JLogConfigInitializer.java 2015-04-15 14:58:13 +0000
@@ -0,0 +1,131 @@
+package org.hisp.dhis.system.log;
+
+/*
+ * Copyright (c) 2004-2015, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * Neither the name of the HISP project nor the names of its contributors may
+ * be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+import java.io.File;
+import java.util.List;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.log4j.Level;
+import org.apache.log4j.Logger;
+import org.apache.log4j.PatternLayout;
+import org.apache.log4j.RollingFileAppender;
+import org.hisp.dhis.external.location.LocationManager;
+import org.springframework.beans.factory.annotation.Autowired;
+
+import com.google.inject.internal.Lists;
+
+/**
+ * @author Lars Helge Overland
+ */
+public class Log4JLogConfigInitializer
+ implements LogConfigInitializer
+{
+ private static final PatternLayout PATTERN_LAYOUT = new PatternLayout( "* %-5p %d{ISO8601} %m (%F [%t])%n" );
+
+ private static final String MAX_FILE_SIZE = "25MB";
+ private static final int MAX_BACKUP_FILES = 3;
+
+ private static final String LOG_DIR = "logs";
+ private static final String ANALYTICS_TABLE_LOGGER_FILENAME = "dhis-analytics-table.log";
+ private static final String DATA_SYNC_LOGGER_FILENAME = "dhis-data-sync.log";
+
+ private static final Log log = LogFactory.getLog( Log4JLogConfigInitializer.class );
+
+ @Autowired
+ private LocationManager locationManager;
+
+ @Override
+ public void initConfig()
+ {
+ if ( !locationManager.externalDirectorySet() )
+ {
+ log.warn( "Could not initialize additional log configuration, external home directory not set" );
+ return;
+ }
+
+ locationManager.buildDirectory( LOG_DIR );
+
+ configureLoggers( ANALYTICS_TABLE_LOGGER_FILENAME, Lists.newArrayList( "org.hisp.dhis.resourcetable", "org.hisp.dhis.analytics.table" ) );
+
+ configureLoggers( DATA_SYNC_LOGGER_FILENAME, Lists.newArrayList( "org.hisp.dhis.dxf2.synch" ) );
+ }
+
+ /**
+ * Configures rolling file loggers.
+ *
+ * @param filename the filename to output logging to.
+ * @param loggers the logger names.
+ */
+ private void configureLoggers( String filename, List<String> loggers )
+ {
+ String file = getLogFile( filename );
+
+ RollingFileAppender appender = getRollingFileAppender( file );
+
+ for ( String loggerName : loggers )
+ {
+ Logger logger = Logger.getRootLogger().getLoggerRepository().getLogger( loggerName );
+
+ logger.addAppender( appender );
+
+ log.info( "Added logger: " + loggerName + " using file: " + file );
+ }
+ }
+
+ /**
+ * Returns a rolling file appender.
+ *
+ * @param file the file to output to, including path and filename.
+ */
+ private RollingFileAppender getRollingFileAppender( String file )
+ {
+ RollingFileAppender appender = new RollingFileAppender();
+
+ appender.setThreshold( Level.INFO );
+ appender.setFile( file );
+ appender.setMaxFileSize( MAX_FILE_SIZE );
+ appender.setMaxBackupIndex( MAX_BACKUP_FILES );
+ appender.setLayout( PATTERN_LAYOUT );
+ appender.activateOptions();
+
+ return appender;
+ }
+
+ /**
+ * Returns a file including path and filename.
+ *
+ * @param filename the filename to use for the file path.
+ */
+ private String getLogFile( String filename )
+ {
+ return locationManager.getExternalDirectoryPath() + File.separator + LOG_DIR + File.separator + filename;
+ }
+}
=== added file 'dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/log/LogConfigInitializer.java'
--- dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/log/LogConfigInitializer.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/log/LogConfigInitializer.java 2015-04-15 14:58:13 +0000
@@ -0,0 +1,40 @@
+package org.hisp.dhis.system.log;
+
+/*
+ * Copyright (c) 2004-2015, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * Neither the name of the HISP project nor the names of its contributors may
+ * be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/**
+ * @author Lars Helge Overland
+ */
+public interface LogConfigInitializer
+{
+ /**
+ * Initializes log configuration.
+ */
+ void initConfig();
+}
=== modified file 'dhis-2/dhis-support/dhis-support-system/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-support/dhis-support-system/src/main/resources/META-INF/dhis/beans.xml 2014-12-04 06:39:46 +0000
+++ dhis-2/dhis-support/dhis-support-system/src/main/resources/META-INF/dhis/beans.xml 2015-04-15 14:58:13 +0000
@@ -33,4 +33,6 @@
<bean id="debugger" class="org.hisp.dhis.system.debug.DebuggerImpl" />
+ <bean id="logInitializer" class="org.hisp.dhis.system.log.Log4JLogConfigInitializer" init-method="initConfig" />
+
</beans>
Follow ups