diff options
author | Csaba Henk <csaba@gluster.com> | 2011-07-13 00:52:14 +0200 |
---|---|---|
committer | Anand Avati <avati@gluster.com> | 2011-07-29 05:24:43 -0700 |
commit | a13fbaca0512cae3853a2372d0d8237eb24dd225 (patch) | |
tree | eb504ec3794346e1199b13ba88cf42c5815f28ea /xlators/features/marker/utils/syncdaemon/syncdutils.py | |
parent | 6c7a89321af50925fb53da378d996881a1907f31 (diff) |
gsyncd: do some basic sanitization on logs
- exceptions raised by us will be logged as single-line error messages
(full stack strace is shown only at DEBUG loglevel)
- common/well understood exceptions are mapped to "user-parsable" error logs
Change-Id: I75f1fb848483372364b2093878d9cfed576c9739
BUG: 2778
Reviewed-on: http://review.gluster.com/125
Tested-by: Gluster Build System <jenkins@build.gluster.com>
Reviewed-by: Anand Avati <avati@gluster.com>
Diffstat (limited to 'xlators/features/marker/utils/syncdaemon/syncdutils.py')
-rw-r--r-- | xlators/features/marker/utils/syncdaemon/syncdutils.py | 32 |
1 files changed, 29 insertions, 3 deletions
diff --git a/xlators/features/marker/utils/syncdaemon/syncdutils.py b/xlators/features/marker/utils/syncdaemon/syncdutils.py index 49ef1662e87..a905745f1b4 100644 --- a/xlators/features/marker/utils/syncdaemon/syncdutils.py +++ b/xlators/features/marker/utils/syncdaemon/syncdutils.py @@ -5,9 +5,10 @@ import fcntl import shutil import logging from threading import Lock, Thread as baseThread -from errno import EACCES, EAGAIN +from errno import EACCES, EAGAIN, EPIPE, ENOTCONN from signal import SIGTERM, SIGKILL from time import sleep +from cPickle import PickleError from gconf import gconf @@ -125,13 +126,35 @@ def finalize(*a, **kw): os._exit(kw.get('exval', 0)) def log_raise_exception(excont): + is_filelog = False + for h in logging.getLogger().handlers: + fno = getattr(getattr(h, 'stream', None), 'fileno', None) + if fno and not os.isatty(fno()): + is_filelog = True + exc = sys.exc_info()[1] if isinstance(exc, SystemExit): excont.exval = exc.code or 0 raise else: - logging.exception("FAIL: ") - sys.stderr.write("failed with %s.\n" % type(exc).__name__) + logtag = None + if isinstance(exc, GsyncdError): + if is_filelog: + logging.error(exc.message) + sys.stderr.write('failure: ' + exc.message + "\n") + elif isinstance(exc, PickleError) or isinstance(exc, EOFError) or \ + ((isinstance(exc, OSError) or isinstance(exc, IOError)) and \ + exc.errno == EPIPE): + logging.error('connection to peer is broken') + elif isinstance(exc, OSError) and exc.errno == ENOTCONN: + logging.error('glusterfs session went down') + else: + logtag = "FAIL" + if not logtag and logging.getLogger().isEnabledFor(logging.DEBUG): + logtag = "FULL EXCEPTION TRACE" + if logtag: + logging.exception(logtag + ": ") + sys.stderr.write("failed with %s.\n" % type(exc).__name__) excont.exval = 1 sys.exit(excont.exval) @@ -160,3 +183,6 @@ class Thread(baseThread): kw['target'] = twrap baseThread.__init__(self, *a, **kw) self.setDaemon(True) + +class GsyncdError(StandardError): + pass |