incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fmesc...@apache.org
Subject svn commit: r634637 - in /incubator/sling/trunk/osgi/log/src/main: java/org/apache/sling/osgi/log/LogbackManager.java resources/OSGI-INF/metatype/metatype.properties resources/OSGI-INF/metatype/metatype.xml
Date Fri, 07 Mar 2008 12:29:41 GMT
Author: fmeschbe
Date: Fri Mar  7 04:29:40 2008
New Revision: 634637

URL: http://svn.apache.org/viewvc?rev=634637&view=rev
Log:
SLING-314 support configuration of number of rotated log files and the
maximum log file size

Modified:
    incubator/sling/trunk/osgi/log/src/main/java/org/apache/sling/osgi/log/LogbackManager.java
    incubator/sling/trunk/osgi/log/src/main/resources/OSGI-INF/metatype/metatype.properties
    incubator/sling/trunk/osgi/log/src/main/resources/OSGI-INF/metatype/metatype.xml

Modified: incubator/sling/trunk/osgi/log/src/main/java/org/apache/sling/osgi/log/LogbackManager.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/osgi/log/src/main/java/org/apache/sling/osgi/log/LogbackManager.java?rev=634637&r1=634636&r2=634637&view=diff
==============================================================================
--- incubator/sling/trunk/osgi/log/src/main/java/org/apache/sling/osgi/log/LogbackManager.java
(original)
+++ incubator/sling/trunk/osgi/log/src/main/java/org/apache/sling/osgi/log/LogbackManager.java
Fri Mar  7 04:29:40 2008
@@ -43,6 +43,7 @@
 import ch.qos.logback.core.rolling.FixedWindowRollingPolicy;
 import ch.qos.logback.core.rolling.RollingFileAppender;
 import ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy;
+import ch.qos.logback.core.util.FileSize;
 
 /**
  * The <code>LogbackManager</code> manages the loggers used by the LogService
@@ -66,12 +67,20 @@
 
     public static final String LOG_FILE = "org.apache.sling.osgi.log.file";
 
+    public static final String LOG_FILE_NUMBER = "org.apache.sling.osgi.log.file.number";
+    
+    public static final String LOG_FILE_SIZE = "org.apache.sling.osgi.log.file.size";
+
     public static final String LOG_PATTERN = "org.apache.sling.osgi.log.pattern";
 
     public static final String LOG_CONFIG_URL = "org.apache.sling.osgi.log.url";
 
     public static final String LOG_PATTERN_DEFAULT = "%d{dd.MM.yyyy HH:mm:ss} *%-5p* %c{1}:
%m%n";
 
+    public static final int LOG_FILE_NUMBER_DEFAULT = 5;
+    
+    public static final String LOG_FILE_SIZE_DEFAULT = "10MB";
+    
     /**
      * default log category - set during init()
      */
@@ -284,15 +293,39 @@
                 logDir.mkdirs();
             }
 
-            // keep 4 old log files
+            // get number of files and ensure minimum and default
+            Object fileNumObj = context.getProperty(LOG_FILE_NUMBER);
+            int fileNum = -1;
+            if (fileNumObj instanceof Number) {
+                fileNum = ((Number) fileNumObj).intValue();
+            } else if (fileNumObj != null) {
+                try {
+                    fileNum = Integer.parseInt(fileNumObj.toString());
+                } catch (NumberFormatException nfe) {
+                    // don't care
+                }
+            }
+            if (fileNum <= 0) {
+                fileNum = LOG_FILE_NUMBER_DEFAULT;
+            }
+            
+            // keep the number old log files
             FixedWindowRollingPolicy rolling = new FixedWindowRollingPolicy();
             rolling.setFileNamePattern(logFileName + ".%i");
-            rolling.setMaxIndex(4);
+            rolling.setMinIndex(0);
+            rolling.setMaxIndex(fileNum - 1);
             rolling.setContext(loggerContext);
 
+            // get the log file size
+            Object fileSizeObj = context.getProperty(LOG_FILE_SIZE);
+            String fileSize = (fileSizeObj != null) ? fileSizeObj.toString() : null;
+            if (fileSize == null || fileSize.length() == 0) {
+                fileSize = LOG_FILE_SIZE_DEFAULT; 
+            }
+                
             // switch log file after 1MB
             SizeBasedTriggeringPolicy trigger = new SizeBasedTriggeringPolicy();
-            trigger.setMaxFileSize("1mb");
+            trigger.setMaxFileSize(fileSize);
             trigger.setContext(loggerContext);
 
             // define the default appender

Modified: incubator/sling/trunk/osgi/log/src/main/resources/OSGI-INF/metatype/metatype.properties
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/osgi/log/src/main/resources/OSGI-INF/metatype/metatype.properties?rev=634637&r1=634636&r2=634637&view=diff
==============================================================================
--- incubator/sling/trunk/osgi/log/src/main/resources/OSGI-INF/metatype/metatype.properties
(original)
+++ incubator/sling/trunk/osgi/log/src/main/resources/OSGI-INF/metatype/metatype.properties
Fri Mar  7 04:29:40 2008
@@ -26,6 +26,16 @@
 log.file.description = The name and path of the log file. If this is empty, \
  logging goes to standard output (the console). If this path is relative it \
  is resolved below ${sling.home}.
+log.file.number.name = Number of Log Files
+log.file.number.description = The number of log files to keep. When the size of \
+ the log file reaches the configured maximum (see Maximum Log File Size), \
+ the log file is copied and a new log file is created. This setting specifies \
+ how many generations (incl. the active log file) should be kept. This is a \
+ positive numeric value. The default value is 5. 
+log.file.size.name=Maximum Log File Size
+log.file.size.description The maximum size of the log file. If this size is \
+ reached the log file is copied and a new log file is created. This size \
+ may be specified with size indicators KB, MB and GB. The default is 10MB.
 log.pattern.name = Message Pattern
 log.pattern.description = Message Pattern for the Pattern Layout. See \
  http://logback.qos.ch/manual/layouts.html#ClassicPatternLayout for more \
@@ -34,4 +44,4 @@
 log.url.description = URL to a Logback configuration file. This URL must be \
  accessible to the Sling server, which is important in the case of file: URLs. \
  If this property is set and the configuration file succeeds configuring \
- Logback, the other configuration properties are actually ignored.
+ Logback, the other configuration properties are actually ignored.
\ No newline at end of file

Modified: incubator/sling/trunk/osgi/log/src/main/resources/OSGI-INF/metatype/metatype.xml
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/osgi/log/src/main/resources/OSGI-INF/metatype/metatype.xml?rev=634637&r1=634636&r2=634637&view=diff
==============================================================================
--- incubator/sling/trunk/osgi/log/src/main/resources/OSGI-INF/metatype/metatype.xml (original)
+++ incubator/sling/trunk/osgi/log/src/main/resources/OSGI-INF/metatype/metatype.xml Fri Mar
 7 04:29:40 2008
@@ -33,6 +33,12 @@
         <metatype:AD id="org.apache.sling.osgi.log.file" type="String"
             default="logs/error.log" name="%log.file.name"
             description="%log.file.description" />
+        <metatype:AD id="org.apache.sling.osgi.log.file.number" type="Integer"
+            default="5" name="%log.file.number.name"
+            description="%log.file.number.description" />
+        <metatype:AD id="org.apache.sling.osgi.log.file.size" type="String"
+            default="10mb" name="%log.file.size.name"
+            description="%log.file.size.description" />
         <metatype:AD id="org.apache.sling.osgi.log.pattern" type="String"
             default="%d{dd.MM.yyyy HH:mm:ss} *%-5p* %c{1}: %m%n"
             name="%log.pattern.name"



Mime
View raw message