summaryrefslogtreecommitdiff
path: root/misc/mon_ami/log.py
diff options
context:
space:
mode:
authorStefan Wintermeyer <stefan.wintermeyer@amooma.de>2012-12-17 12:01:45 +0100
committerStefan Wintermeyer <stefan.wintermeyer@amooma.de>2012-12-17 12:01:45 +0100
commitb80bd744ad873f6fc43018bc4bfb90677de167bd (patch)
tree072c4b0e33d442528555b82c415f5e7a1712b2b0 /misc/mon_ami/log.py
parent3e706c2025ecc5523e81ad649639ef2ff75e7bac (diff)
Start of GS5.
Diffstat (limited to 'misc/mon_ami/log.py')
-rw-r--r--misc/mon_ami/log.py71
1 files changed, 71 insertions, 0 deletions
diff --git a/misc/mon_ami/log.py b/misc/mon_ami/log.py
new file mode 100644
index 0000000..92709ad
--- /dev/null
+++ b/misc/mon_ami/log.py
@@ -0,0 +1,71 @@
+# -*- coding: utf-8 -*-
+# Log library
+# (c) AMOOMA GmbH 2012
+
+import logging
+
+def ldebug(entry, initiator = None):
+ global logger
+ logger.debug('%s(%d) %s' % (type(initiator).__name__, id(initiator), entry))
+
+def lwarn(entry, initiator = None):
+ global logger
+ logger.warning('%s(%d) %s' % (type(initiator).__name__, id(initiator), entry))
+
+def lerror(entry, initiator = None):
+ global logger
+ logger.error('%s(%d) %s' % (type(initiator).__name__, id(initiator), entry))
+
+def linfo(entry, initiator = None):
+ global logger
+ logger.info('%s(%d) %s' % (type(initiator).__name__, id(initiator), entry))
+
+def lcritic(entry, initiator = None):
+ global logger
+ logger.critical('%s(%d) %s' % (type(initiator).__name__, id(initiator), entry))
+
+def setup_log(file_name = None, loglevel = 5, logformat = None):
+ from sys import stdout
+ global logger
+
+ if file_name:
+ try:
+ logfile = logging.FileHandler(file_name)
+ except:
+ logfile = logging.StreamHandler(stdout)
+ else: logfile = logging.StreamHandler(stdout)
+
+ loglevel = int(loglevel)
+
+ if (loglevel == 0):
+ logfile.setLevel(logging.NOTSET)
+ logger.setLevel(logging.NOTSET)
+ elif (loglevel == 1):
+ logfile.setLevel(logging.CRITICAL)
+ logger.setLevel(logging.CRITICAL)
+ elif (loglevel == 2):
+ logfile.setLevel(logging.ERROR)
+ logger.setLevel(logging.ERROR)
+ elif (loglevel == 3):
+ logfile.setLevel(logging.WARNING)
+ logger.setLevel(logging.WARNING)
+ elif (loglevel == 4):
+ logfile.setLevel(logging.INFO)
+ logger.setLevel(logging.INFO)
+ elif (loglevel >= 5):
+ logfile.setLevel(logging.DEBUG)
+ logger.setLevel(logging.DEBUG)
+
+ if not logformat:
+ logformat = '%(asctime)s-%(name)s-%(levelname)s-%(message)s'
+
+ try:
+ format = logging.Formatter(logformat)
+ logfile.setFormatter(format)
+ except:
+ format = logging.Formatter('%(asctime)s-%(name)s-%(levelname)s-%(message)s')
+ logfile.setFormatter(format)
+
+ logger.addHandler(logfile)
+
+logger = logging.getLogger('#')