示例#1
0
    def setup_logger(self):
        '''
            Sets up the logger to later use it for any kind of logging. 
        '''
        if self.verbosity is None:
            self.logger = None
            return
        self.logger = getLogger(self.name)
        self.logger.setLevel(DEBUG)
        self.logger.propagate = False
        if not self.logger.handlers:
            fh = FileHandler(os.path.join(self.basepath, 'logging.log'))
            fh.setLevel(DEBUG)
            ch = StreamHandler(sys.stdout)
            ch_level = {'info': INFO, 'debug': DEBUG}[self.verbosity]
            ch.setLevel(ch_level)

            che = StreamHandler(sys.stderr)
            che.setLevel(WARNING)
            formatter = Formatter('[%(asctime)s {}] %(message)s'.format(
                self.name))
            formatter.datefmt = '%y/%m/%d %H:%M:%S'
            fh.setFormatter(formatter)
            ch.setFormatter(formatter)
            che.setFormatter(formatter)
            self.logger.addHandler(fh)
            self.logger.addHandler(ch)
            self.logger.addHandler(che)
示例#2
0
 def __init__(self):
     StreamHandler.__init__(self)
     formatter = Formatter(
         '%(asctime)s.%(msecs)03d:%(levelname)-8s%(lineno)-4d: %(message)s',
     )
     formatter.datefmt = '%H:%M:%S'
     self.setFormatter(formatter)
     self.setLevel(DEBUG)
示例#3
0
def config_logging(log_dname="logs"):
    log_dname = "{0}/".format(log_dname)
    if not os.path.exists(log_dname):
        os.mkdir(log_dname)
    logpath = os.getcwd() + "/{0}/".format(log_dname) + time.asctime() + '.log'
    datefmt = '%m/%d/%g@%H:%M'
    fh = FileHandler(logpath)
    fh.setLevel(logging.DEBUG)
    fmt = Formatter('%(asctime)s:%(levelname)s - %(module)s:%(funcName)s - %(message)s')
    fmt.datefmt = datefmt
    fh.setFormatter(fmt)
    app.logger.addHandler(fh)
    return app