summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/util.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2006-03-03 00:24:41 +0000
committerMike Bayer <mike_mp@zzzcomputing.com>2006-03-03 00:24:41 +0000
commit13710ae742c18eb589a204bc9d242cccf66ae4b0 (patch)
tree0551f34d1d06ffd150da63d13b7d2f17aee979a0 /lib/sqlalchemy/util.py
parent64792659d12c02534de2124e9f53b17105c0946b (diff)
downloadsqlalchemy-13710ae742c18eb589a204bc9d242cccf66ae4b0.tar.gz
added util.Logger object with configurable thread/timestamp view
Diffstat (limited to 'lib/sqlalchemy/util.py')
-rw-r--r--lib/sqlalchemy/util.py31
1 files changed, 29 insertions, 2 deletions
diff --git a/lib/sqlalchemy/util.py b/lib/sqlalchemy/util.py
index 618900fcf..02bd5d587 100644
--- a/lib/sqlalchemy/util.py
+++ b/lib/sqlalchemy/util.py
@@ -5,7 +5,7 @@
# the MIT License: http://www.opensource.org/licenses/mit-license.php
__all__ = ['OrderedProperties', 'OrderedDict', 'generic_repr', 'HashSet', 'AttrProp']
-import thread, weakref, UserList,string, inspect
+import thread, threading, weakref, UserList, time, string, inspect, sys
from exceptions import *
def to_list(x):
@@ -51,7 +51,34 @@ def hash_key(obj):
return obj.hash_key()
else:
return repr(obj)
-
+
+class Logger(object):
+ """defines various forms of logging"""
+ def __init__(self, logger=None, usethreads=False, usetimestamp=True, origin=None):
+ self.logger = logger or sys.stdout
+ self.usethreads = usethreads
+ self.usetimestamp = usetimestamp
+ self.origin = origin
+ def write(self, msg):
+ if self.usetimestamp:
+ t = time.time()
+ ms = (t - long(t)) * 1000
+ timestamp = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(t))
+ timestamp = "[%s,%03d]" % (timestamp, ms)
+ else:
+ timestamp = None
+ if self.origin:
+ origin = "[%s]" % self.origin
+ origin = "%-8s" % origin
+ else:
+ origin = None
+ if self.usethreads:
+ threadname = threading.currentThread().getName()
+ threadname = "[" + threadname + ' '*(8-len(threadname)) + "]"
+ else:
+ threadname = None
+ self.logger.write(string.join([s for s in (timestamp, threadname, origin) if s is not None]) + ": " + msg + "\n")
+
class OrderedProperties(object):
"""
An object that maintains the order in which attributes are set upon it.