home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2011 October / maximum-cd-2011-10.iso / DiscContents / digsby_setup.exe / lib / csvlogging.pyo (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2011-06-22  |  3.8 KB  |  100 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.6)
  3.  
  4. import logging
  5. import gzip
  6. from time import strftime
  7. from traceback import format_exception
  8. COMMA = '#comma#'
  9. LINE = '#line#'
  10.  
  11. def csv_escape(s):
  12.     return s.replace(',', COMMA).replace('\n', LINE)
  13.  
  14. CSV_HEADERS = 'Time, Log Level, Level Name, Log Name, Message,Pathname, Filename, Module, Function Name, Line No., Timestamp, Thread Count, Thread Name, Thread No., Process No.\n'
  15.  
  16. class CSVFormatter(logging.Formatter):
  17.     _fmt = '%(asctime)s,%(levelno)s,%(levelname)s,%(name)s,%(message)s,%(pathname)s,%(filename)s,%(module)s,%(funcName)s,%(lineno)d,%(created)f,%(threadCount)d,%(threadName)s,%(thread)d,%(process)d'
  18.     
  19.     def __init__(self, fmt = None, datefmt = None):
  20.         logging.Formatter.__init__(self, fmt, datefmt)
  21.         self._fmt = CSVFormatter._fmt
  22.         self._asctime = self._fmt.find('%(asctime)') >= 0
  23.  
  24.     
  25.     def formatTime(self, record, datefmt = None):
  26.         ct = self.converter(record.created)
  27.         if datefmt:
  28.             s = strftime(datefmt, ct)
  29.         else:
  30.             t = strftime('%Y-%m-%d %H:%M:%S', ct)
  31.             s = '%s.%03d' % (t, record.msecs)
  32.         return s
  33.  
  34.     
  35.     def formatException(self, ei):
  36.         s = '\n'.join(format_exception(*ei))
  37.         if s.endswith('\n'):
  38.             s = s[:-1]
  39.         
  40.         return s
  41.  
  42.     
  43.     def format(self, record):
  44.         record.message = ''.join(('"', record.getMessage().replace('"', '""'), '"'))
  45.         if self._asctime:
  46.             record.asctime = self.formatTime(record, self.datefmt)
  47.         
  48.         s = self._fmt % record.__dict__
  49.         if record.exc_info:
  50.             if not record.exc_text:
  51.                 record.exc_text = csv_escape(self.formatException(record.exc_info))
  52.             
  53.         
  54.         if record.exc_text:
  55.             if not s.endswith(','):
  56.                 s = s + ','
  57.             
  58.             s = ''.join((s, record.exc_text))
  59.         
  60.         return s
  61.  
  62.  
  63.  
  64. class gzipFileHandler(logging.StreamHandler):
  65.     
  66.     def __init__(self, t, filename = None):
  67.         if not filename:
  68.             filename = 'digsby-' + t + '.log.csv.gz'
  69.         
  70.         f = open('logs/digsby-' + t + '.log.csv.gz', 'wb')
  71.         self.gzfileobj = gzip.GzipFile(filename, fileobj = f)
  72.         self.gzfileobj.write('Time, Log Level, Level Name, Log Name, Message,Pathname, Filename, Module, Function Name, Line No., Timestamp, Thread No., Thread Name, Process No.\n')
  73.         logging.StreamHandler.__init__(self, self.gzfileobj)
  74.  
  75.     
  76.     def close(self):
  77.         logging.StreamHandler.close(self)
  78.         self.gzfileobj.close()
  79.  
  80.  
  81.  
  82. class CloseFileHandler(logging.StreamHandler):
  83.     
  84.     def __init__(self, openfile, level = None, formatter = None):
  85.         self.fileobj = openfile
  86.         logging.StreamHandler.__init__(self, self.fileobj)
  87.         if level is not None:
  88.             self.setLevel(level)
  89.         
  90.         if formatter is not None:
  91.             self.setFormatter(formatter)
  92.         
  93.  
  94.     
  95.     def close(self):
  96.         logging.StreamHandler.close(self)
  97.         self.fileobj.close()
  98.  
  99.  
  100.