]> Frank Brehm's Git Trees - my-stuff/py-logrotate.git/commitdiff
dateext behandelt
authorFrank Brehm <frank@brehm-online.com>
Sat, 7 May 2011 23:28:57 +0000 (23:28 +0000)
committerFrank Brehm <frank@brehm-online.com>
Sat, 7 May 2011 23:28:57 +0000 (23:28 +0000)
git-svn-id: http://svn.brehm-online.com/svn/my-stuff/python/PyLogrotate/trunk@228 ec8d2aa5-1599-4edb-8739-2b3a1bc399aa

LogRotateConfig.py
test/apache2

index 47e31950946e8bab63917ff9adbe940b18398336..edb3da18c3691d8237f4ab75d2cec15d5186a7e5 100755 (executable)
@@ -98,21 +98,37 @@ path_options = (
 )
 
 valid_periods = {
-  'hourly':   (1/24),
-  '2hourly':  (1/12),
-  '4hourly':  (1/6),
-  '6hourly':  (1/4),
-  '12hourly': (1/2),
-  'daily':    1,
-  '2daily':   2,
-  'weekly':   7,
-  'monthly':  30,
-  '2monthly': 60,
-  '4monthly': 120,
-  '6monthly': 182,
-  'yearly':   365,
+    'hourly':   (1/24),
+    '2hourly':  (1/12),
+    '4hourly':  (1/6),
+    '6hourly':  (1/4),
+    '12hourly': (1/2),
+    'daily':    1,
+    '2daily':   2,
+    'weekly':   7,
+    'monthly':  30,
+    '2monthly': 60,
+    '4monthly': 120,
+    '6monthly': 182,
+    'yearly':   365,
 }
 
+yes_values = (
+    '1',
+    'on',
+    'y',
+    'yes',
+    'true',
+)
+
+no_values = (
+    '0',
+    'off',
+    'n',
+    'no',
+    'false',
+)
+
 
 #========================================================================
 
@@ -1200,6 +1216,97 @@ class LogrotateConfigurationReader(object):
             directive['period'] = option_value
             return True
 
+        # get maximum age of old rotated log files
+        match = re.search(r'^(not?)?maxage$', option, re.IGNORECASE)
+        if match:
+            negated = False
+            if match.group(1) is not None:
+                negated = True
+            if (val is None) or re.search(r'^\s*$', val) is not None:
+                negated = True
+            option_value = 0
+            if not negated:
+                try:
+                    option_value = period2days(val, verbose = self.verbose)
+                except ValueError, e:
+                    self.logger.warning(
+                        ( _("Invalid maxage definition: »%s«") %(val) )
+                    )
+                    return False
+            if self.verbose > 4:
+                self.logger.debug(
+                    ( _("Setting »maxage« to %f days. (file »%s«, line %s)")
+                      % (option_value, filename, linenr)
+                    )
+                )
+            directive['maxage'] = option_value
+            return True
+
+        # Setting date extension of rotated log files
+        match = re.search(r'^(no)?dateext$', option, re.IGNORECASE)
+        if match:
+
+            negated = False
+            if match.group(1) is not None:
+                negated = True
+            use_dateext = False
+            dateext = None
+
+            if self.verbose > 4:
+                self.logger.debug(
+                    ( _("Checking »dateext«, negated: »%s«. "
+                        + "(file »%s«, line %s)")
+                      % (str(negated), filename, linenr)
+                    )
+                )
+            values = []
+            if val is not None:
+                values = split_parts(val) 
+
+            if not negated:
+                first_val = ''
+                if len(values) > 0:
+                    first_val = values[0].lower()
+                option_value = first_val
+                if first_val is None or \
+                        re.search(r'^\s*$', first_val) is not None:
+                    option_value = 'true'
+                if self.verbose > 4:
+                    self.logger.debug(
+                        ( _("»dateext«: first_val: »%s«, option_value: »%s«. "
+                            + "(file »%s«, line %s)")
+                            % (first_val, option_value, filename, linenr)
+                        )
+                    )
+                if option_value in yes_values:
+                    use_dateext = True
+                elif option_value in no_values:
+                    use_dateext = False
+                else:
+                    use_dateext = True
+                    dateext = val
+
+            if self.verbose > 4:
+                self.logger.debug(
+                    ( _("Setting »dateext« to »%s«. (file »%s«, line %s)")
+                      % (str(use_dateext), filename, linenr)
+                    )
+                )
+            directive['dateext'] = use_dateext
+
+            if dateext is not None:
+                if self.verbose > 4:
+                    self.logger.debug(
+                        ( _("Setting »datepattern« to »%s«. "
+                            + "(file »%s«, line %s)")
+                            % (dateext, filename, linenr)
+                        )
+                    )
+                directive['datepattern'] = dateext
+
+            return True
+                    
+
         return True
 
     #------------------------------------------------------------
index fce39be2944a3f533f53ebd91bc244467cdb9e8c..89319826610fc64ca4b453453fde49cd999a2723 100644 (file)
@@ -9,10 +9,13 @@
   notifempty
   sharedscripts
   rotate 10
-  error bla
+  #dateext '%Y%m%d'
+  dateext
+  #error bla
   weekly
   #period 4.5days 2 hours 3.4y
   size 1m
+  maxage 0.5y
   mail test@uhu-banane.de
   olddir /var/log/apache2/%Y-%m
   postrotate