summaryrefslogtreecommitdiff
path: root/portato/helper.py
diff options
context:
space:
mode:
authornecoro <>2007-07-13 04:09:51 +0000
committernecoro <>2007-07-13 04:09:51 +0000
commitfc6d232a9357211a44dad3300ff64571620aa1bf (patch)
tree2f31112805b8d05c94978775a183668dc260367c /portato/helper.py
parentb5e8e2eb2b8bc9936070028ecf91ff8d0b7c33ef (diff)
downloadportato-fc6d232a9357211a44dad3300ff64571620aa1bf.tar.gz
portato-fc6d232a9357211a44dad3300ff64571620aa1bf.tar.bz2
portato-fc6d232a9357211a44dad3300ff64571620aa1bf.zip
new fancier log output
Diffstat (limited to 'portato/helper.py')
-rw-r--r--portato/helper.py69
1 files changed, 4 insertions, 65 deletions
diff --git a/portato/helper.py b/portato/helper.py
index cc797b9..f25fa34 100644
--- a/portato/helper.py
+++ b/portato/helper.py
@@ -12,74 +12,13 @@
"""
Some nice functions used in the program.
-
-@var DEBUG: Boolean controlling whether to printout debug messages.
-@type DEBUG: boolean
"""
-import traceback, os.path, sys, types
-import os, signal
-
-DEBUG = True
-
-def set_debug (d):
- """Sets the global DEBUG variable. Do not set it by your own - always use this function.
-
- @param d: True to enable debugging; False otherwise
- @type d: boolean"""
-
- global DEBUG
- DEBUG = d
-
-def debug(*args, **kwargs):
- """Prints a debug message including filename and lineno.
- A variable number of positional arguments are allowed.
-
- If debug(obj0, obj1, obj2) is called, the text part of the output
- looks like the output from print obj0, obj1, obj2.
-
- @keyword name: Use the given name instead the correct function name.
- @keyword file: Output file to use.
- @keyword minus: The value given is the amount of frames to ignore in the stack to return the correct function call.
- This should be used if you are wrapping the debug call.
- @keyword warn: Prints the message as a warning. Value of DEBUG is ignored.
- @keyword error: Prints the message as an error. Value of DEBUG is ignored."""
-
- if not DEBUG and not ("warn" in kwargs or "error" in kwargs): return
-
- stack = traceback.extract_stack()
- minus = -2
- if "minus" in kwargs:
- minus = minus - kwargs["minus"]
- a, b, c, d = stack[minus]
- a = os.path.basename(a)
- out = []
- for obj in args:
- out.append(str(obj))
- text = ' '.join(out)
- if "name" in kwargs:
- text = 'In %s (%s:%s): %s' % (kwargs["name"], a, b, text)
- else:
- text = 'In %s (%s:%s): %s' % (c, a, b, text)
-
- outfile = sys.stdout
- surround = "DEBUG"
+import types, os, signal, logging
+from logging import debug, info, warning, error, critical, exception
- if "warn" in kwargs:
- outfile = sys.stderr
- surround = "WARNING"
- elif "error" in kwargs:
- outfile = sys.stderr
- surround = "ERROR"
-
- text = ("***%s*** %s ***%s***" % (surround, text, surround))
-
- if "file" in kwargs:
- f = open(kwargs["file"], "a+")
- f.write(text+"\n")
- f.close()
- else:
- print >> outfile, text
+def set_log_level (lvl):
+ logging.getLogger().setLevel(lvl)
def send_signal_to_group (sig):
"""Sends a signal to all processes of our process group (w/o ourselves).