⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 log.py

📁 在 linux平台上的网页编程的模板
💻 PY
字号:
#!/neo/opt/bin/python# log.pyimport sys, time, stringDEV = "development"DEV_UPDATE = "update queries"DEV_SELECT = "select queries"DEV_REPORT = "report log"LOGGING_STATUS = {   DEV : 1,   DEV_UPDATE : 0,   DEV_SELECT : 0,   DEV_REPORT : 0}tstart = 0def dlog(when,astr):    global LOGGING_STATUS    try:        if LOGGING_STATUS[when]:            log(astr)    except KeyError:        passdef tlog(astr):    global tstart    t = time.time()    if tstart == 0:        tstart = t    time_stamp = "%5.5f" % (t-tstart)    if len(astr):        if astr[-1] == "\n":            sys.stderr.write("[%s] %s" % (time_stamp, astr))        else:            sys.stderr.write("[%s] %s\n" % (time_stamp, astr))def orig_log(astr):    if len(astr) > 1024:        astr = astr[:1024]    t = time.time()    time_stamp = time.strftime("%m/%d %T", time.localtime(t))    if len(astr):        if astr[-1] == "\n":            sys.stderr.write("[%s] %s" % (time_stamp, astr))        else:            sys.stderr.write("[%s] %s\n" % (time_stamp, astr))    # sys.stderr.flush()#----------------------------------------------------------------------# static functions_gDebug = 0_gFileDebug = 0kBLACK = 0kRED = 1kGREEN = 2kYELLOW = 3kBLUE = 4kMAGENTA = 5kCYAN = 6kWHITE = 7kBRIGHT = 8def ansicolor (str, fgcolor = None, bgcolor = None):  o = ""  if fgcolor:    if fgcolor & kBRIGHT:      bright = ';1'    else:      bright = ''    o = o + '%c[3%d%sm' % (chr(27), fgcolor & 0x7, bright)  if bgcolor:    o = o + '%c[4%dm' % (chr(27), bgcolor)  o = o + str  if fgcolor or bgcolor:    o = o + '%c[0m' % (chr(27))  return odef _log(*args):  t = time.time()  log_line = ""  log_line = log_line + "[" + time.strftime("%m/%d %T", time.localtime(t)) + "] "  l = []  for arg in args:    l.append(str(arg))  log_line = log_line + string.join(l, " ") + "\n"  sys.stderr.write(log_line)def warn(*args):  apply(_log, args)def warnred(*args):  args = tuple ([""] + list(args) + [""])  apply(_log, args)def log(*args):  apply(_log, args)def logred(*args):  if _gDebug>=1:     args = tuple ([""] + list(args) + [""])    apply(_log, args)def debug(*args):  if _gDebug>=2: apply(_log, args)def debugfull():  global _gDebug  _gDebug = 2def debugon():  global _gDebug  _gDebug = 1def debugoff():  global _gDebug  _gDebug = 0

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -