From fe1bd860aacc72028afbcdb90a6d800b72651518 Mon Sep 17 00:00:00 2001 From: Isis Lovecruft Date: Fri, 25 Jan 2013 11:13:12 +0000 Subject: Cleaned up logging functions and added docstrings. --- src/leap/util/log.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'src/leap/util') diff --git a/src/leap/util/log.py b/src/leap/util/log.py index 62ac113..15db367 100644 --- a/src/leap/util/log.py +++ b/src/leap/util/log.py @@ -26,7 +26,6 @@ from twisted.python.failure import Failure from leap.util import version, config -## xxx TODO finish docstrings class InvalidTimestampFormat(Exception): pass @@ -59,13 +58,21 @@ def prettyDateNow(): return datetime.now().ctime() def utcPrettyDateNow(): - """Pretty string for utc time.""" + """Pretty string for UTC.""" return datetime.utcnow().ctime() def timeToPrettyDate(time_val): + """Convert seconds since epoch to date.""" return time.ctime(time_val) def start(logfile=None, application_name=None): + """ + Start logging to stdout, and optionally to a logfile as well. + + @param logfile: The filename to store logs in, which is placed in + /leap_mx/logs/. + @param application_name: The name of the running application. + """ if not application_name: application_name = version.name print "application name: %s" % application_name @@ -86,24 +93,28 @@ def start(logfile=None, application_name=None): txlog.msg("Starting %s on %s (%s UTC)" % (application_name, prettyDateNow(), utcPrettyDateNow())) - ## xxx need these functions! ^^ def msg(msg, *arg, **kwarg): + """Log a message at the INFO level.""" print "[*] %s" % msg def debug(msg *arg, **kwarg): + """Log a message at the DEBUG level.""" if config.basic.debug: print "[d] %s" % msg def warn(msg, *arg, **kwarg): + """Log a message at the WARN level.""" if config.basic.show_warnings: txlog.logging.captureWarnings('true') print "[#] %s" % msg def err(msg, *arg, **kwarg): + """Log a message at the ERROR level.""" print "[!] %s" % msg def fail(*failure): + """Log a message at the CRITICAL level.""" logging.critical(failure) ## xxx should we take steps to exit here? -- cgit v1.2.3