diff options
author | Isis Lovecruft <isis@torproject.org> | 2013-01-25 01:50:19 +0000 |
---|---|---|
committer | Isis Lovecruft <isis@torproject.org> | 2013-01-25 01:50:19 +0000 |
commit | 383e614b3fc53ca2d59104988d8ec1a3a9cba14d (patch) | |
tree | ceedbc82bd9f4a17908061bb370669efe70801b7 /src/leap/util/log.py | |
parent | a849cdf75955e110b5ed9ceabfcbcdbd219cbcc6 (diff) |
Added timestamp formatting functions to logger.
Diffstat (limited to 'src/leap/util/log.py')
-rw-r--r-- | src/leap/util/log.py | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/src/leap/util/log.py b/src/leap/util/log.py index 661b0a1..62ac113 100644 --- a/src/leap/util/log.py +++ b/src/leap/util/log.py @@ -10,11 +10,13 @@ Logging for leap_mx. @copyright: 2013 Isis Agora Lovecruft ''' +from datetime import datetime from functools import wraps import logging import os import sys +import time import traceback from twisted.python import log as txlog @@ -24,8 +26,13 @@ from twisted.python.failure import Failure from leap.util import version, config +## xxx TODO finish docstrings + +class InvalidTimestampFormat(Exception): + pass class UnprefixedLogfile(txlog.FileLogObserver): + """Logfile with plain messages, without timestamp prefixes.""" def emit(self, eventDict): text = txlog.textFromEventDict(eventDict) if text is None: @@ -35,6 +42,29 @@ class UnprefixedLogfile(txlog.FileLogObserver): txutil.untilConcludes(self.flush) +def utcDateNow(): + """The current date for UTC time.""" + return datetime.utcnow() + +def utcTimeNow(): + """Seconds since epoch in UTC time, as type float.""" + return time.mktime(time.gmtime()) + +def dateToTime(date): + """Convert datetime to seconds since epoch.""" + return time.mktime(date.timetuple()) + +def prettyDateNow(): + """Pretty string for the local time.""" + return datetime.now().ctime() + +def utcPrettyDateNow(): + """Pretty string for utc time.""" + return datetime.utcnow().ctime() + +def timeToPrettyDate(time_val): + return time.ctime(time_val) + def start(logfile=None, application_name=None): if not application_name: application_name = version.name |