log.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 # log.py
4 
5 import sys, time, string
6 
7 DEV = "development"
8 DEV_UPDATE = "update queries"
9 DEV_SELECT = "select queries"
10 DEV_REPORT = "report log"
11 
12 LOGGING_STATUS = {
13  DEV : 1,
14  DEV_UPDATE : 0,
15  DEV_SELECT : 0,
16  DEV_REPORT : 0}
17 
18 tstart = 0
19 
20 def dlog(when,astr):
21  global LOGGING_STATUS
22  try:
23  if LOGGING_STATUS[when]:
24  log(astr)
25  except KeyError:
26  pass
27 
28 def tlog(astr):
29  global tstart
30  t = time.time()
31  if tstart == 0:
32  tstart = t
33  time_stamp = "%5.5f" % (t-tstart)
34  if len(astr):
35  if astr[-1] == "\n":
36  sys.stderr.write("[%s] %s" % (time_stamp, astr))
37  else:
38  sys.stderr.write("[%s] %s\n" % (time_stamp, astr))
39 
40 def orig_log(astr):
41  if len(astr) > 1024:
42  astr = astr[:1024]
43 
44  t = time.time()
45  time_stamp = time.strftime("%m/%d %T", time.localtime(t))
46  if len(astr):
47  if astr[-1] == "\n":
48  sys.stderr.write("[%s] %s" % (time_stamp, astr))
49  else:
50  sys.stderr.write("[%s] %s\n" % (time_stamp, astr))
51  # sys.stderr.flush()
52 
53 
54 #----------------------------------------------------------------------
55 # static functions
56 
57 _gDebug = 0
58 _gFileDebug = 0
59 
60 kBLACK = 0
61 kRED = 1
62 kGREEN = 2
63 kYELLOW = 3
64 kBLUE = 4
65 kMAGENTA = 5
66 kCYAN = 6
67 kWHITE = 7
68 kBRIGHT = 8
69 
70 def ansicolor (str, fgcolor = None, bgcolor = None):
71  o = ""
72  if fgcolor:
73  if fgcolor & kBRIGHT:
74  bright = ';1'
75  else:
76  bright = ''
77  o = o + '%c[3%d%sm' % (chr(27), fgcolor & 0x7, bright)
78  if bgcolor:
79  o = o + '%c[4%dm' % (chr(27), bgcolor)
80  o = o + str
81  if fgcolor or bgcolor:
82  o = o + '%c[0m' % (chr(27))
83  return o
84 
85 
86 def _log(*args):
87  t = time.time()
88 
89  log_line = ""
90 
91  log_line = log_line + "[" + time.strftime("%m/%d %T", time.localtime(t)) + "] "
92 
93  l = []
94  for arg in args:
95  l.append(str(arg))
96  log_line = log_line + string.join(l, " ") + "\n"
97 
98  sys.stderr.write(log_line)
99 
100 def warn(*args):
101  apply(_log, args)
102 
103 def warnred(*args):
104  args = tuple ([""] + list(args) + [""])
105  apply(_log, args)
106 
107 def log(*args):
108  if _gDebug>=1:
109  apply(_log, args)
110 
111 def logred(*args):
112  if _gDebug>=1:
113  args = tuple ([""] + list(args) + [""])
114  apply(_log, args)
115 
116 def debug(*args):
117  if _gDebug>=2: apply(_log, args)
118 
119 
120 def debugfull():
121  global _gDebug
122  _gDebug = 2
123 
124 def debugon():
125  global _gDebug
126  _gDebug = 1
127 
128 def debugoff():
129  global _gDebug
130  _gDebug = 0
131 
def dlog(when, astr)
Definition: log.py:20
def log(args)
Definition: log.py:107
def ansicolor(str, fgcolor=None, bgcolor=None)
Definition: log.py:70
def orig_log(astr)
Definition: log.py:40
def debugon()
Definition: log.py:124
def logred(args)
Definition: log.py:111
def debugfull()
Definition: log.py:120
def warn(args)
Definition: log.py:100
def tlog(astr)
Definition: log.py:28
def debugoff()
Definition: log.py:128
def _log(args)
Definition: log.py:86
def warnred(args)
Definition: log.py:103
def debug(args)
Definition: log.py:116


pyclearsilver
Author(s): Scott Noob Hassan
autogenerated on Mon Jun 10 2019 15:51:13