Ejemplo n.º 1
0
 def __init__(self, channel='private'):
     filename = BOTNAME
     if channel:
         filename += '_' + channel
     if not os.path.isdir('log'):
         os.mkdir('log')
     self.loggers = {}
     for name, suffix in [("normal", ""), ("filtered", "_filtered")]:
         f = str(os.path.join('log', "%s%s.log" % (filename, suffix)))
         self.loggers[name] = getLogger("%s%s" % (channel, suffix))
         if not len(self.loggers[name].handlers):
             self.loggers[name].addHandler(
                 RotatingFileHandler(f, backupCount=1000, encoding="utf-8"))
         self.loggers[name].handlers[0].setFormatter(
             Formatter('%(asctime)s %(message)s', "%Y-%m-%d %H:%M:%S"))
         channel = channel if channel != "private" else None
         if os.path.isfile(f) and os.path.getsize(f) > 1024 * 1024:
             logg("Rolling log file %s" % f,
                  color="yellow",
                  action="LOGS",
                  channel=channel)
             try:
                 self.loggers[name].handlers[0].doRollover()
             except Exception as e:
                 loggerr("Rolling file %s crashed: %s\n%s" %
                         (f, self.loggers[name].handlers, e),
                         action="LOGS",
                         channel=channel)
Ejemplo n.º 2
0
 def __init__(self, channel='private'):
     filename = BOTNAME
     if channel:
         filename += '_' + channel
     if not os.path.isdir('log'):
         os.mkdir('log')
     self.loggers = {}
     for name, suffix in [("normal", ""), ("filtered", "_filtered")]:
         f = str(os.path.join('log', "%s%s.log" % (filename, suffix)))
         self.loggers[name] = getLogger("%s%s" % (channel, suffix))
         if not len(self.loggers[name].handlers):
             self.loggers[name].addHandler(RotatingFileHandler(f, backupCount=1000, encoding="utf-8"))
         self.loggers[name].handlers[0].setFormatter(Formatter('%(asctime)s %(message)s', "%Y-%m-%d %H:%M:%S"))
         channel = channel if channel != "private" else None
         if os.path.isfile(f) and os.path.getsize(f) > 1024*1024:
             logg("Rolling log file %s" % f, color="yellow", action="LOGS", channel=channel)
             try:
                 self.loggers[name].handlers[0].doRollover()
             except Exception as e:
                 loggerr("Rolling file %s crashed: %s\n%s" % (f, self.loggers[name].handlers, e), action="LOGS", channel=channel)
Ejemplo n.º 3
0
 def log(self, msg, error=False, hint=False):
     color = None
     if hint:
         color = 'yellow'
     if error and not config.DEBUG:
         hmd5 = md5(str(msg)).hexdigest()
         if hmd5 not in self.errorlogs or self.errorlogs[hmd5]['ts'] < time.time() - 3600*24:
             self.errorlogs[hmd5] = {'n': 1, 'ts': time.time()}
         else:
             self.errorlogs[hmd5]['n'] += 1
             if self.errorlogs[hmd5]['n'] > 3:
                 return
             elif self.errorlogs[hmd5]['n'] == 3:
                 msg += " [#3, skipping these errors now for the next 24h...]"
             else:
                 msg += " [#%d]" % self.errorlogs[hmd5]['n']
             self.errorlogs[hmd5]['ts'] = time.time()
     return logg(msg, channel=self.channel, action=self.name, error=error, color=color)
Ejemplo n.º 4
0
 def log(self, msg, error=False, hint=False):
     color = None
     if hint:
         color = 'yellow'
     if error and not config.DEBUG:
         hmd5 = md5(str(msg)).hexdigest()
         if hmd5 not in self.errorlogs or self.errorlogs[hmd5]['ts'] < time.time() - 3600*24:
             self.errorlogs[hmd5] = {'n': 1, 'ts': time.time()}
         else:
             self.errorlogs[hmd5]['n'] += 1
             if self.errorlogs[hmd5]['n'] > 3:
                 return
             elif self.errorlogs[hmd5]['n'] == 3:
                 msg += " [#3, skipping these errors now for the next 24h...]"
             else:
                 msg += " [#%d]" % self.errorlogs[hmd5]['n']
             self.errorlogs[hmd5]['ts'] = time.time()
     return logg(msg, channel=self.channel, action=self.name, error=error, color=color)
Ejemplo n.º 5
0
 def log(self, msg, action="", error=False, hint=False):
     color = None
     if hint:
         color= 'yellow'
     return logg(msg, channel=self.channel, action=action, error=error, color=color)