commit e2f8780f9b26316a67e14cdafe2ba06815cb0dbf Author: Konstantin Ryabitsev mricon@kernel.org Date: Fri Feb 10 22:07:29 2012 -0500
Do not return an error on 0-length log files.
ChangeLog | 10 ++- configure.in | 2 +- epylog.spec | 199 ------------------------------------------------- py/epylog/__init__.py | 11 +++- py/epylog/log.py | 32 +++++--- py/epylog/module.py | 7 ++ 6 files changed, 45 insertions(+), 216 deletions(-) --- diff --git a/ChangeLog b/ChangeLog index a855c09..aca45a9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +Epylog-1.0.7 + * Re-apply a fix to not return an error with a 0-length log file. + * Remove unmaintained spec file. + Epylog-1.0.6 * Back out the unfinished work to support timestamped rotation (will be implemented fully in 1.1). Fixes the cron-run problem @@ -30,14 +34,14 @@ Epylog-1.0.1 not work. * Automatically detect python version during .spec building. * Cleaned up trojans.list so it's less ugly - + Epylog-1.0 * Out with 1.0 already! * Handle ::ffff: fake ipv6 addresses for hostname resolution * Do not depend on elinks in RPM. * Default setting is to send html-only (so we don't depend on lynx) * Packets module can now sort by port, system, and source. - + Epylog-0.9.7 * Accepted Makefile patches from Will Newton * Accepted patches for missing logs from Will Newton (#135) @@ -57,7 +61,7 @@ Epylog-0.9.5 * Fix for bug #57 * Fix for bug #53 * Cron mode of operation added -- checks for a lockfile (bug #79) - + Epylog-0.9.4 * Fix for bug #38 (incorrect offsets were causing backtrace) * Normalized logger calls (bug #9) diff --git a/configure.in b/configure.in index 50c5d4b..b003f4e 100644 --- a/configure.in +++ b/configure.in @@ -2,7 +2,7 @@ dnl Process this file with autoconf to produce a configure script
AC_INIT(epylog.spec) PACKAGE_TARNAME=epylog -PACKAGE_VERSION=1.0.6 +PACKAGE_VERSION=1.0.7
dnl Package information. PACKAGE=$PACKAGE_TARNAME diff --git a/py/epylog/__init__.py b/py/epylog/__init__.py index a8cc68c..ab762de 100644 --- a/py/epylog/__init__.py +++ b/py/epylog/__init__.py @@ -47,7 +47,7 @@ from report import Report from module import Module from log import LogTracker
-VERSION = 'Epylog-1.0.6' +VERSION = 'Epylog-1.0.7' CHUNK_SIZE = 8192 GREP_LINES = 10000 QUEUE_LIMIT = 500 @@ -125,6 +125,15 @@ class NoSuchLogError(exceptions.Exception): logger.put(5, '!NoSuchLogError: %s' % message) self.args = message
+class EmptyLogError(exceptions.Exception): + """ + This exception is raised when Epylog finds an empty logfile. + """ + def __init__(self, message, logger): + exceptions.Exception.__init__(self) + logger.put(5, '!EmptyLogError: %s' % message) + self.args = message + class GenericError(exceptions.Exception): """ This exception is raised for all other Epylog conditions. diff --git a/py/epylog/log.py b/py/epylog/log.py index 30b2e39..f0750a8 100644 --- a/py/epylog/log.py +++ b/py/epylog/log.py @@ -436,10 +436,19 @@ class Log: self.entry = entry filename = self._get_filename() logger.puthang(3, 'Initializing the logfile "%s"' % filename) - logfile = LogFile(filename, tmpprefix, monthmap, logger) + self.loglist = [] + self.cur_rot_ix = 0 + try: + logfile = LogFile(filename, tmpprefix, monthmap, logger) + logger.put(3, 'Appending logfile to the loglist') + self.loglist.append(logfile) + except epylog.EmptyLogError: + logger.endhang(3) + logger.puthang(3, '%s is empty, using the previous rotated log' + % filename) + self._init_next_rotfile() + logfile = self.loglist[0] logger.endhang(3) - logger.put(3, 'Appending logfile to the loglist') - self.loglist = [logfile] self.orange = OffsetRange(0, 0, 0, logfile.end_offset, logger) logger.endhang(3) self.lp = None @@ -805,24 +814,24 @@ class Log: """ logger = self.logger logger.put(5, '>Log._init_next_rotfile') - ix = len(self.loglist) - rotname = self._get_rotname_by_ix(ix) + self.cur_rot_ix += 1 + rotname = self._get_rotname_by_ix(self.cur_rot_ix) try: logger.put(3, 'Initializing log for rotated file "%s"' % rotname) rotlog = LogFile(rotname, self.tmpprefix, self.monthmap, logger) + self.loglist.append(rotlog) except epylog.AccessError: msg = 'No further rotated files for entry "%s"' % self.entry raise epylog.NoSuchLogError(msg, logger) - self.loglist.append(rotlog) + except epylog.EmptyLogError: + msg = 'Found an empty rotated log, ignoring it.' + rotlog = self._init_next_rotfile() logger.put(5, '<Log._init_next_rotfile') return rotlog
def _get_rotname_by_ix(self, ix): """ - The good thing about rotated files is that they are exactly at the same - position in the log list, as the identifier appended to them by - logrotate. E.g. messages.1 will be at position 1, messages.2 at - position 2, and just messages at position 0. + Figure out the rotated file name by index passed. """ logger = self.logger logger.put(5, '>Log._get_rotname_by_ix') @@ -1300,8 +1309,7 @@ class LogFile: logger.put(3, 'Making it 0') stamp = 0 else: - logger.put(5, 'Nothing in the range') - stamp = 0 + raise epylog.EmptyLogError('%s is empty' % self.filename, logger) logger.put(5, '<LogFile._get_stamp') return stamp
diff --git a/py/epylog/module.py b/py/epylog/module.py index 7eaded2..600c5a1 100644 --- a/py/epylog/module.py +++ b/py/epylog/module.py @@ -123,6 +123,13 @@ class Module: # logger.put(0, 'Could not init logfile for entry "%s"' % entry) continue + except epylog.NoSuchLogError: + ## + # Looks like all logfiles for this log entry are empty. + # Ignore this log entry. + logger.put(1, ('No logs found for %s, or they are all empty, '+ + 'ignoring.') % entry) + continue logger.put(5, 'Appending the log object to self.logs[]') self.logs.append(log) if len(self.logs) == 0: