forked from m0mchil/poclbm
-
Notifications
You must be signed in to change notification settings - Fork 151
/
log.py
35 lines (29 loc) · 866 Bytes
/
log.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
from datetime import datetime
from threading import RLock
import sys
import traceback
quiet = False
verbose = False
server = ''
lock = RLock()
TIME_FORMAT = '%d/%m/%Y %H:%M:%S'
def say(format_, args=(), say_quiet=False):
if quiet and not say_quiet: return
with lock:
p = format_ % args
if verbose:
print '%s %s,' % (server, datetime.now().strftime(TIME_FORMAT)), p
else:
sys.stdout.write('\r%s\r%s %s' % (' '*80, server, p))
sys.stdout.flush()
def say_line(format_, args=()):
if not verbose:
format_ = '%s, %s\n' % (datetime.now().strftime(TIME_FORMAT), format_)
say(format_, args)
def say_exception(message=''):
type_, value, tb = sys.exc_info()
say_line(message + ' %s', str(value))
if verbose:
traceback.print_exception(type_, value, tb)
def say_quiet(format_, args=()):
say(format_, args, True)