aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnthony G. Basile <blueness@gentoo.org>2015-07-09 10:49:23 -0400
committerAnthony G. Basile <blueness@gentoo.org>2015-07-09 10:49:23 -0400
commitc59ed6dad57d443a0fef14f9b120f5e6b026abc9 (patch)
tree1817f8761f41918f8d249718d5b8157d45f520c7 /grs/Log.py
parentgrs/RunScript.py: check if the script exists before trying to unlink it. (diff)
downloadgrss-c59ed6dad57d443a0fef14f9b120f5e6b026abc9.tar.gz
grss-c59ed6dad57d443a0fef14f9b120f5e6b026abc9.tar.bz2
grss-c59ed6dad57d443a0fef14f9b120f5e6b026abc9.zip
grs/Rotator.py: consolidate common rotation code.
Diffstat (limited to 'grs/Log.py')
-rw-r--r--grs/Log.py16
1 files changed, 2 insertions, 14 deletions
diff --git a/grs/Log.py b/grs/Log.py
index 2a7ef9d..81ac022 100644
--- a/grs/Log.py
+++ b/grs/Log.py
@@ -7,7 +7,7 @@ import re
import shutil
from grs.Constants import CONST
-class Log():
+class Log(Rotator):
def __init__(self, logfile = CONST.LOGFILE):
self.logfile = logfile
@@ -25,19 +25,7 @@ class Log():
def rotate_logs(self):
- logs = glob.glob('%s.*' % self.logfile)
- indexed_log = {}
- for l in logs:
- m = re.search('^.+\.(\d+)$', l)
- indexed_log[int(m.group(1))] = l
- count = list(indexed_log.keys())
- count.sort()
- count.reverse()
- for c in count:
- current_log = indexed_log[c]
- m = re.search('^(.+)\.\d+$', current_log)
- next_log = '%s.%d' % (m.group(1), c+1)
- shutil.move(current_log, next_log)
+ self.rotate(self.logfile)
if os.path.isfile(self.logfile):
shutil.move(self.logfile, '%s.0' % self.logfile)
open('%s' % self.logfile, 'a').close()