Python logging 模块,addLevelName() 实例源码

我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用logging.addLevelName()

项目:memes-reposter    作者:vaniakosmos    | 项目源码 | 文件源码
def set_up_logging(debug):
    if debug:
        logging_level = logging.DEBUG
    else:
        logging_level = logging.INFO

    logging.basicConfig(format='%(asctime)s ~ %(levelname)-10s %(name)-25s %(message)s',
                        datefmt='%Y-%m-%d %H:%M',
                        level=logging_level)

    logging.getLogger('telegram').setLevel(logging.WARNING)
    logging.getLogger('requests').setLevel(logging.WARNING)
    logging.getLogger('JobQueue').setLevel(logging.WARNING)

    logging.addLevelName(logging.DEBUG, '?? DEBUG')
    logging.addLevelName(logging.INFO, '?? INFO')
    logging.addLevelName(logging.WARNING, '?? WARNING')
    logging.addLevelName(logging.ERROR, '?? ERROR')
项目:sahara_emulator    作者:bkerler    | 项目源码 | 文件源码
def prepare_logging():
    global umap2_logger
    global stdio_handler
    if umap2_logger is None:
        def add_debug_level(num, name):
            def fn(self, message, *args, **kwargs):
                if self.isEnabledFor(num):
                    self._log(num, message, args, **kwargs)
            logging.addLevelName(num, name)
            setattr(logging, name, num)
            return fn

        logging.Logger.verbose = add_debug_level(5, 'VERBOSE')
        logging.Logger.always = add_debug_level(100, 'ALWAYS')

        FORMAT = '[%(levelname)-6s] %(message)s'
        stdio_handler = logging.StreamHandler()
        stdio_handler.setLevel(logging.INFO)
        formatter = logging.Formatter(FORMAT)
        stdio_handler.setFormatter(formatter)
        umap2_logger = logging.getLogger('umap2')
        umap2_logger.addHandler(stdio_handler)
        umap2_logger.setLevel(logging.VERBOSE)
    return umap2_logger
项目:odooku-compat    作者:adaptivdesign    | 项目源码 | 文件源码
def setup(debug=False, statsd_host=None):
    level = 'DEBUG' if debug else 'INFO'
    dictConfig(dict(
        version=1,
        disable_existing_loggers=True,
        loggers={
            '': {
                'level': level,
                'handlers': ['console']
            },
        },
        handlers={
            'console': {
                'class': 'logging.StreamHandler',
                'formatter': 'simple',
                'stream': sys.stdout
            },
        },
        formatters={
            'simple': {
                'format': '[%(process)d] [%(levelname)s] %(message)s',
                'class': 'logging.Formatter'
            },
        }
    ))

    OdookuLogger._statsd_host = statsd_host
    logging.setLoggerClass(OdookuLogger)
    logging.addLevelName(25, 'INFO')

    # Prevent odoo from overriding log config
    import openerp.netsvc
    openerp.netsvc._logger_init = True
项目:pdfminify    作者:johndoe31415    | 项目源码 | 文件源码
def configure_logging(verbosity_loglevel):
    llvl = LogLevel.getbyverbosity(verbosity_loglevel)

    logging.TRACE = logging.DEBUG - 1
    logging.addLevelName(logging.TRACE, "TRACE")

    logging_loglevel = {
        LogLevel.Silent:    logging.WARNING,
        LogLevel.Normal:    logging.INFO,
        LogLevel.Verbose:   logging.DEBUG,
        LogLevel.Debug:     logging.TRACE,
    }[llvl]

    def __log_trace(self, message, *args, **kwargs):
        if self.isEnabledFor(logging.TRACE):
            self._log(logging.TRACE, message, args, **kwargs)
    logging.Logger.trace = __log_trace

    logging.basicConfig(format = " {name:>20s} [{levelname:.1s}]: {message}", style = "{", level = logging_loglevel)
项目:mlib    作者:mak    | 项目源码 | 文件源码
def get_logger(name, level=INFO, fac=SysLogHandler.LOG_LOCAL1):

    global LOG_TRANS

    for lt in LOG_TRANS:
        if not LOG_TRANS[lt]['old']:
            LOG_TRANS[lt]['old'] = logging.getLevelName(lt)
        logging.addLevelName(lt, LOG_TRANS[lt]['new'])

    fmt = F('[%(name)s.%(funcName)s]: %(message)s')
    log = logging.getLogger('%s' % name.split('.')[-1])
    h = SysLogHandler(address='/dev/log', facility=parse_fac(fac))
    h.setFormatter(fmt)
    log.addHandler(h)
#    h = StreamHandler(stream=LOGBUF)
#    h.setFormatter(fmt)
#    log.addHandler(h)
    log.setLevel(level)
    log.success = lambda msg: log.log(LOG_SUCCES, msg)
    return log
项目:s2e-env    作者:S2E    | 项目源码 | 文件源码
def _configure_logging(level=logging.INFO, use_color=True):
    """
    Configure te global logging settings.
    """
    # Add a 'SUCCESS' level to the logger
    logging.addLevelName(log.SUCCESS, 'SUCCESS')
    logging.Logger.success = log.success

    # Configure colored logging
    logger = logging.getLogger()
    logger.setLevel(level)

    # Overwrite any existing handlers
    if logger.handlers:
        logger.handlers = []

    colored_handler = logging.StreamHandler()
    colored_handler.setFormatter(ColoredFormatter(use_color=use_color))
    logger.addHandler(colored_handler)
项目:maas    作者:maas    | 项目源码 | 文件源码
def make_logging_level_names_consistent():
    """Rename the standard library's logging levels to match Twisted's.

    Twisted's new logging system in `twisted.logger` that is.
    """
    for level in list(logging._levelToName):
        if level == logging.NOTSET:
            # When the logging level is not known in Twisted it's rendered as
            # a hyphen. This is not a common occurrence with `logging` but we
            # cater for it anyway.
            name = "-"
        elif level == logging.WARNING:
            # "Warning" is more consistent with the other level names than
            # "warn", so there is a fault in Twisted here. However it's easier
            # to change the `logging` module to match Twisted than vice-versa.
            name = "warn"
        else:
            # Twisted's level names are all lower-case.
            name = logging.getLevelName(level).lower()
        # For a preexisting level this will _replace_ the name.
        logging.addLevelName(level, name)
项目:physpetools    作者:yangfangs    | 项目源码 | 文件源码
def setlogdir(logdir):
    '''set the log directory'''
    # set log color
    logging.addLevelName(logging.INFO, print_style('%s', fore='green') % logging.getLevelName(logging.INFO))
    logging.addLevelName(logging.WARNING, print_style('%s', fore='red') % logging.getLevelName(logging.WARNING))
    ldir = os.path.dirname(logdir)
    writelog = os.path.join(ldir, 'log.log')
    logging.basicConfig(level=logging.DEBUG,
                        format='%(asctime)s %(name)s[line:%(lineno)d] %(levelname)s %(message)s',
                        datefmt='%a, %d %b %Y %H:%M:%S',
                        filename=writelog,
                        filemode='w')

    console = logging.StreamHandler()

    console.setLevel(logging.INFO)

    formatter = logging.Formatter('%(asctime)s %(name)s %(levelname)s: %(message)s')

    console.setFormatter(formatter)

    logging.getLogger('').addHandler(console)
项目:kinect-2-libras    作者:inessadl    | 项目源码 | 文件源码
def get_logger():
    '''
    Returns logger used by multiprocessing
    '''
    global _logger
    import logging, atexit

    logging._acquireLock()
    try:
        if not _logger:

            _logger = logging.getLogger(LOGGER_NAME)
            _logger.propagate = 0
            logging.addLevelName(SUBDEBUG, 'SUBDEBUG')
            logging.addLevelName(SUBWARNING, 'SUBWARNING')

            # XXX multiprocessing should cleanup before logging
            if hasattr(atexit, 'unregister'):
                atexit.unregister(_exit_function)
                atexit.register(_exit_function)
            else:
                atexit._exithandlers.remove((_exit_function, (), {}))
                atexit._exithandlers.append((_exit_function, (), {}))

    finally:
        logging._releaseLock()

    return _logger
项目:bitcoin-arbitrage    作者:ucfyao    | 项目源码 | 文件源码
def inject_verbose_info(self):
        logging.VERBOSE = 15
        logging.verbose = lambda x: logging.log(logging.VERBOSE, x)
        logging.addLevelName(logging.VERBOSE, "VERBOSE")
项目:wr-lx-setup    作者:Wind-River    | 项目源码 | 文件源码
def setup_logging(level=PLAIN_LOG_LEVEL, output=sys.stdout):
    """create the setup.py singleton logger."""
    global logger
    if logger:
        return logger

    logger = logging.getLogger('setup.py')

    formatter = ScreenFormatter(plain_log_level=PLAIN_LOG_LEVEL)
    stream_h = logging.StreamHandler(output)
    stream_h.setFormatter(formatter)

    # Logging timezone is UTC
    stream_h.converter = time.gmtime


    logger.setLevel(level)
    logger.addHandler(stream_h)

    logging.addLevelName(PLAIN_LOG_LEVEL, "PLAIN")
    logging.Logger.plain = plain

    logging.addLevelName(TO_FILE_LOG_LEVEL, 'TO_FILE')
    logging.Logger.to_file = to_file

    return logger
项目:belogging    作者:georgeyk    | 项目源码 | 文件源码
def __init__(self, capture_warnings=True, use_default_kvp=True, json=False):
        self._config = deepcopy(DEFAULT_LOGGING_CONF)

        if use_default_kvp:
            self.update_default_formatter(DEFAULT_KVP_FORMAT)

        if json:
            self.enable_json_formatter()

        # Custom level to suppress handlers
        logging.addLevelName('DISABLED', LEVEL_MAP['DISABLED'])
        logging.captureWarnings(capture_warnings)
项目:hostapd-mana    作者:adde88    | 项目源码 | 文件源码
def get_logger():
    '''
    Returns logger used by multiprocessing
    '''
    global _logger
    import logging, atexit

    logging._acquireLock()
    try:
        if not _logger:

            _logger = logging.getLogger(LOGGER_NAME)
            _logger.propagate = 0
            logging.addLevelName(SUBDEBUG, 'SUBDEBUG')
            logging.addLevelName(SUBWARNING, 'SUBWARNING')

            # XXX multiprocessing should cleanup before logging
            if hasattr(atexit, 'unregister'):
                atexit.unregister(_exit_function)
                atexit.register(_exit_function)
            else:
                atexit._exithandlers.remove((_exit_function, (), {}))
                atexit._exithandlers.append((_exit_function, (), {}))

    finally:
        logging._releaseLock()

    return _logger
项目:sc-controller    作者:kozec    | 项目源码 | 文件源码
def init_logging(prefix="", suffix=""):
    """
    Initializes logging, sets custom logging format and adds one
    logging level with name and method to call.

    prefix and suffix arguments can be used to modify log level prefixes.
    """
    logging.basicConfig(format=LOG_FORMAT)
    logger = logging.getLogger()
    # Rename levels
    logging.addLevelName(10, prefix + "D" + suffix) # Debug
    logging.addLevelName(20, prefix + "I" + suffix) # Info
    logging.addLevelName(30, prefix + "W" + suffix) # Warning
    logging.addLevelName(40, prefix + "E" + suffix) # Error
    # Create additional, "verbose" level
    logging.addLevelName(15, prefix + "V" + suffix) # Verbose
    # Add 'logging.verbose' method
    def verbose(self, msg, *args, **kwargs):
        return self.log(15, msg, *args, **kwargs)
    logging.Logger.verbose = verbose
    # Wrap Logger._log in something that can handle utf-8 exceptions
    old_log = logging.Logger._log
    def _log(self, level, msg, args, exc_info=None, extra=None):
        args = tuple([
            (str(c).decode("utf-8") if type(c) is str else c)
            for c in args
        ])
        msg = msg if type(msg) is unicode else str(msg).decode("utf-8")
        old_log(self, level, msg, args, exc_info, extra)
    logging.Logger._log = _log
项目:python-application    作者:AGProjects    | 项目源码 | 文件源码
def __setattr__(self, name, value):
        if name == 'name' and 'name' in self.__dict__:
            logging.addLevelName(int(self), value)
        super(NamedLevel, self).__setattr__(name, value)
项目:postcards    作者:abertschi    | 项目源码 | 文件源码
def _create_logger(self, logger=None):
        logging.addLevelName(LOGGING_TRACE_LVL, 'TRACE')
        logger = logger or logging.getLogger(inflection.underscore(type(self).__name__))
        setattr(logger, 'trace', lambda *args: logger.log(LOGGING_TRACE_LVL, *args))
        return logger
项目:pyuf    作者:uArm-Developer    | 项目源码 | 文件源码
def logger_init(level = logging.INFO):
    logging.basicConfig(format = '%(name)s: %(levelname)s: %(message)s', level = level)
    logging.addLevelName(logging.VERBOSE, 'VERBOSE')
项目:artman    作者:googleapis    | 项目源码 | 文件源码
def __init__(self, name, level=logging.NOTSET):
        super(Logger, self).__init__(name, level)
        logging.addLevelName(OUTPUT, 'OUTPUT')
        logging.addLevelName(SUCCESS, 'SUCCESS')
项目:stratosphere    作者:victortrac    | 项目源码 | 文件源码
def main(project, env, action, verbose, format, template_path):
    if verbose >= 2:
        level = 5
    elif verbose == 1:
        level = logging.DEBUG
    else:
        logging.getLogger('googleapiclient').setLevel(logging.ERROR)
        logging.getLogger('oauth2client').setLevel(logging.ERROR)
        level = logging.INFO

    logging.addLevelName(5, "TRACE")
    logging.basicConfig(format='%(asctime)s %(levelname)s:%(name)s:%(message)s',
                        datefmt='%Y-%m-%d %H:%M:%S', level=level)

    logger.debug('Debug log enabled')
    logger.info("Log level: {}".format(level))

    if action in ['apply', 'template']:
        if template_path is None:
            logging.error('A path to a template file is required for {}'.format(action))
            sys.exit(1)
        template_class = load_template_module(template_path)
        template = template_class(project, env)

        if format == "json":
            template.formatter = template.asJSON

        if action == 'apply':
            template.__repr__()
            apply_deployment(project, template)
        elif action == 'template':
            t = template.__repr__()
            logger.info('Template successfully rendered, printing to stdout...')
            print(t)
            sys.exit(0)
项目:rst2bash    作者:openstack    | 项目源码 | 文件源码
def configure_logging(log_file):
    """Configure root logger"""
    logger = logging.getLogger()

    logger.setLevel(logging.DEBUG)

    # Level name colored differently (both console and file)
    logging.addLevelName(logging.WARNING, '\x1b[0;33m%s\x1b[0m' %
                         logging.getLevelName(logging.WARNING))
    logging.addLevelName(logging.ERROR, '\x1b[0;31m%s\x1b[0m' %
                         logging.getLevelName(logging.ERROR))

    # Configure console logging
    console_log_handler = logging.StreamHandler()
    console_log_handler.setLevel(logging.INFO)
    # All console messages are the same color (except with colored level names)
    console_formatter = logging.Formatter('\x1b[0;32m%(levelname)s'
                                          '\t%(message)s\x1b[0m')
    console_log_handler.setFormatter(console_formatter)
    logger.addHandler(console_log_handler)

    # Configure log file
    if os.path.isfile(log_file):
        os.remove(log_file)

    file_log_handler = logging.FileHandler(log_file)
    file_log_handler.setLevel(logging.DEBUG)
    file_formatter = logging.Formatter('%(process)s %(asctime)s.%(msecs)03d'
                                       ' %(name)s %(levelname)s %(message)s',
                                       datefmt="%H:%M:%S")
    file_log_handler.setFormatter(file_formatter)
    logger.addHandler(file_log_handler)

    logger.debug("Root logger configured.")


# TODO(dbite): Remove CamelCasing.
# -----------------------------------------------------------------------------
#   Custom data-types.
# -----------------------------------------------------------------------------
项目:docker-weasyprint    作者:aquavitae    | 项目源码 | 文件源码
def setup_logging():
    logging.addLevelName(logging.DEBUG, "\033[1;36m%s\033[1;0m" % logging.getLevelName(logging.DEBUG))
    logging.addLevelName(logging.INFO, "\033[1;32m%s\033[1;0m" % logging.getLevelName(logging.INFO))
    logging.addLevelName(logging.WARNING, "\033[1;33m%s\033[1;0m" % logging.getLevelName(logging.WARNING))
    logging.addLevelName(logging.ERROR, "\033[1;31m%s\033[1;0m" % logging.getLevelName(logging.ERROR))

    handler = logging.StreamHandler()
    handler.setFormatter(logging.Formatter(
        '%(asctime)s %(levelname)s: %(message)s '
        '[in %(pathname)s:%(lineno)d]'
    ))
    app.logger.addHandler(handler)
    app.logger.setLevel(logging.DEBUG)
项目:Bitcoin-arbitrage---opportunity-detector    作者:yoshi717    | 项目源码 | 文件源码
def inject_verbose_info(self):
        logging.VERBOSE = 15
        logging.verbose = lambda x: logging.log(logging.VERBOSE, x)
        logging.addLevelName(logging.VERBOSE, "VERBOSE")
项目:pyswd    作者:pavelrevak    | 项目源码 | 文件源码
def configure():
    """configure logging levels"""
    logging.addLevelName(DEBUG1, 'DEBUG1')
    logging.addLevelName(DEBUG2, 'DEBUG2')
    logging.addLevelName(DEBUG3, 'DEBUG3')
    logging.addLevelName(DEBUG4, 'DEBUG4')
    logging.addLevelName(DEBUG5, 'DEBUG5')
项目:zippy    作者:securesystemslab    | 项目源码 | 文件源码
def get_logger():
    '''
    Returns logger used by multiprocessing
    '''
    global _logger
    import logging, atexit

    logging._acquireLock()
    try:
        if not _logger:

            _logger = logging.getLogger(LOGGER_NAME)
            _logger.propagate = 0
            logging.addLevelName(SUBDEBUG, 'SUBDEBUG')
            logging.addLevelName(SUBWARNING, 'SUBWARNING')

            # XXX multiprocessing should cleanup before logging
            if hasattr(atexit, 'unregister'):
                atexit.unregister(_exit_function)
                atexit.register(_exit_function)
            else:
                atexit._exithandlers.remove((_exit_function, (), {}))
                atexit._exithandlers.append((_exit_function, (), {}))

    finally:
        logging._releaseLock()

    return _logger
项目:zippy    作者:securesystemslab    | 项目源码 | 文件源码
def setUp(self):
        BaseTest.setUp(self)
        for k, v in my_logging_levels.items():
            logging.addLevelName(k, v)
项目:salicapi    作者:Lafaiet    | 项目源码 | 文件源码
def instantiate( cls, streamType = "SCREEN", logLevel = "INFO" ):
        try:
            logging.VERBOSE = 5
            logging.addLevelName(logging.VERBOSE, "VERBOSE")
            logging.Logger.verbose = lambda inst, msg, *args, **kwargs: inst.log(logging.VERBOSE, msg, *args, **kwargs)
            logging.verbose = lambda msg, *args, **kwargs: logging.log(logging.VERBOSE, msg, *args, **kwargs)

            cls.logger = logging.getLogger()

            if logLevel not in logging._levelNames:
                raise Exception( 'Invalid file level' )

            cls.logger.setLevel( logging._levelNames[logLevel] )

            streamType = app.config['STREAMTYPE']

            if streamType == "SCREEN":
                stream = logging.StreamHandler()
            else:
                stream = logging.FileHandler( app.config['LOGFILE'] )

            formatter = logging.Formatter( '[%(levelname)-7s - %(asctime)s] %(message)s' )
            stream.setFormatter( formatter )
            cls.logger.addHandler( stream )
        except Exception, e:
            print( 'Unable to get/set log configurations. Error: %s'%( e ) )
            cls.logger = None


    ##
    # Records a message in a file and/or displays it in the screen.
    # @param level - String containing the name of the log message.
    # @param message - String containing the message to be recorded.
    #
项目:PyMal    作者:cysinfo    | 项目源码 | 文件源码
def setup(level = 0):
    """Sets up the global logging environment"""
    formatstr = "%(levelname)-8s: %(name)-20s: %(message)s"
    logging.basicConfig(format = formatstr)
    rootlogger = logging.getLogger('')
    rootlogger.setLevel(logging.DEBUG + 1 - level)
    for i in range(1, 9):
        logging.addLevelName(logging.DEBUG - i, "DEBUG" + str(i))
项目:oil    作者:oilshell    | 项目源码 | 文件源码
def get_logger():
    '''
    Returns logger used by multiprocessing
    '''
    global _logger
    import logging, atexit

    logging._acquireLock()
    try:
        if not _logger:

            _logger = logging.getLogger(LOGGER_NAME)
            _logger.propagate = 0
            logging.addLevelName(SUBDEBUG, 'SUBDEBUG')
            logging.addLevelName(SUBWARNING, 'SUBWARNING')

            # XXX multiprocessing should cleanup before logging
            if hasattr(atexit, 'unregister'):
                atexit.unregister(_exit_function)
                atexit.register(_exit_function)
            else:
                atexit._exithandlers.remove((_exit_function, (), {}))
                atexit._exithandlers.append((_exit_function, (), {}))

    finally:
        logging._releaseLock()

    return _logger
项目:oil    作者:oilshell    | 项目源码 | 文件源码
def setUp(self):
        BaseTest.setUp(self)
        for k, v in my_logging_levels.items():
            logging.addLevelName(k, v)
项目:python2-tracer    作者:extremecoders-re    | 项目源码 | 文件源码
def get_logger():
    '''
    Returns logger used by multiprocessing
    '''
    global _logger
    import logging, atexit

    logging._acquireLock()
    try:
        if not _logger:

            _logger = logging.getLogger(LOGGER_NAME)
            _logger.propagate = 0
            logging.addLevelName(SUBDEBUG, 'SUBDEBUG')
            logging.addLevelName(SUBWARNING, 'SUBWARNING')

            # XXX multiprocessing should cleanup before logging
            if hasattr(atexit, 'unregister'):
                atexit.unregister(_exit_function)
                atexit.register(_exit_function)
            else:
                atexit._exithandlers.remove((_exit_function, (), {}))
                atexit._exithandlers.append((_exit_function, (), {}))

    finally:
        logging._releaseLock()

    return _logger
项目:python2-tracer    作者:extremecoders-re    | 项目源码 | 文件源码
def setUp(self):
        BaseTest.setUp(self)
        for k, v in my_logging_levels.items():
            logging.addLevelName(k, v)
项目:actsys    作者:intel-ctrlsys    | 项目源码 | 文件源码
def __init__(self, name=None, level=logging.NOTSET):
        super(DataStoreLogger, self).__init__(name, level)
        logging.addLevelName(DataStore.LOG_LEVEL_JOURNAL, "JOURNAL")
项目:sslstrip-hsts-openwrt    作者:adde88    | 项目源码 | 文件源码
def get_logger():
    '''
    Returns logger used by multiprocessing
    '''
    global _logger
    import logging, atexit

    logging._acquireLock()
    try:
        if not _logger:

            _logger = logging.getLogger(LOGGER_NAME)
            _logger.propagate = 0
            logging.addLevelName(SUBDEBUG, 'SUBDEBUG')
            logging.addLevelName(SUBWARNING, 'SUBWARNING')

            # XXX multiprocessing should cleanup before logging
            if hasattr(atexit, 'unregister'):
                atexit.unregister(_exit_function)
                atexit.register(_exit_function)
            else:
                atexit._exithandlers.remove((_exit_function, (), {}))
                atexit._exithandlers.append((_exit_function, (), {}))

    finally:
        logging._releaseLock()

    return _logger
项目:odooku    作者:odooku    | 项目源码 | 文件源码
def setup(debug=False, statsd_host=None):
    level = 'DEBUG' if debug else 'INFO'
    dictConfig(dict(
        version=1,
        disable_existing_loggers=True,
        loggers={
            '': {
                'level': level,
                'handlers': ['console']
            },
        },
        handlers={
            'console': {
                'class': 'logging.StreamHandler',
                'formatter': 'standard',
                # Log to stderr so that click commands can make
                # use of stdout
                'stream': sys.stderr
            },
        },
        formatters={
            'standard': {
                'format': '[%(levelname)s]%(db)s%(message)s',
                '()': 'odooku.logger.DBFormatter'
            },
        }
    ))

    OdookuLogger._statsd_host = statsd_host
    logging.setLoggerClass(OdookuLogger)
    logging.addLevelName(25, 'INFO')

    # Prevent odoo from overriding log config
    import odoo.netsvc
    odoo.netsvc._logger_init = True
项目:web_ctp    作者:molebot    | 项目源码 | 文件源码
def get_logger():
    '''
    Returns logger used by multiprocessing
    '''
    global _logger
    import logging

    logging._acquireLock()
    try:
        if not _logger:

            _logger = logging.getLogger(LOGGER_NAME)
            _logger.propagate = 0
            logging.addLevelName(SUBDEBUG, 'SUBDEBUG')
            logging.addLevelName(SUBWARNING, 'SUBWARNING')

            # XXX multiprocessing should cleanup before logging
            if hasattr(atexit, 'unregister'):
                atexit.unregister(_exit_function)
                atexit.register(_exit_function)
            else:
                atexit._exithandlers.remove((_exit_function, (), {}))
                atexit._exithandlers.append((_exit_function, (), {}))

    finally:
        logging._releaseLock()

    return _logger
项目:web_ctp    作者:molebot    | 项目源码 | 文件源码
def setUp(self):
        BaseTest.setUp(self)
        for k, v in my_logging_levels.items():
            logging.addLevelName(k, v)
项目:Raspberry-Pi-Security-Camera    作者:lelandg    | 项目源码 | 文件源码
def setup_log_colors():
    logging.addLevelName(logging.DEBUG, '\033[1;37m%s\033[1;0m' % logging.getLevelName(logging.DEBUG))
    logging.addLevelName(logging.INFO, '\033[1;36m%s\033[1;0m' % logging.getLevelName(logging.INFO))
    logging.addLevelName(logging.WARNING, '\033[1;31m%s\033[1;0m' % logging.getLevelName(logging.WARNING))
    logging.addLevelName(logging.ERROR, '\033[1;41m%s\033[1;0m' % logging.getLevelName(logging.ERROR))
项目:DSAP    作者:CIRALabs    | 项目源码 | 文件源码
def monkeypatch_resp_logging_level(): 
            logging.RESP = const.LOGGING.RESP_STREAM_LEVEL 
            logging.addLevelName(logging.RESP, "RESP") 
            logging.Logger.resp = lambda inst, msg, *args, **kwargs: inst.log(logging.RESP, msg, *args, **kwargs) 
            logging.resp = lambda msg, *args, **kwargs: logging.log(logging.RESP, msg, *args, **kwargs)
项目:crypto-arbitrager    作者:artooze    | 项目源码 | 文件源码
def inject_verbose_info(self):
        logging.VERBOSE = 15
        logging.verbose = lambda x: logging.log(logging.VERBOSE, x)
        logging.addLevelName(logging.VERBOSE, "VERBOSE")
项目:qudi    作者:Ulm-IQO    | 项目源码 | 文件源码
def initialize_logger():
    """sets up the logger including a console, file and qt handler
    """
    # initialize logger
    logging.basicConfig(format="%(message)s", level=logging.INFO)
    logging.addLevelName(logging.CRITICAL, 'critical')
    logging.addLevelName(logging.ERROR, 'error')
    logging.addLevelName(logging.WARNING, 'warning')
    logging.addLevelName(logging.INFO, 'info')
    logging.addLevelName(logging.DEBUG, 'debug')
    logging.addLevelName(logging.NOTSET, 'not set')
    logging.captureWarnings(True)
    logger = logging.getLogger()
    logger.setLevel(logging.INFO)
    # set level of stream handler which logs to stderr
    logger.handlers[0].setLevel(logging.WARNING)

    # add file logger
    rotating_file_handler = logging.handlers.RotatingFileHandler(
        'qudi.log', maxBytes=10*1024*1024, backupCount=5)
    rotating_file_handler.setFormatter(logging.Formatter(
        '%(asctime)s %(levelname)s %(name)s %(message)s',
        datefmt="%Y-%m-%d %H:%M:%S"))
    rotating_file_handler.doRollover()
    rotating_file_handler.setLevel(logging.DEBUG)
    logger.addHandler(rotating_file_handler)

    # add Qt log handler
    qt_log_handler = QtLogHandler()
    qt_log_handler.setLevel(logging.DEBUG)
    logging.getLogger().addHandler(qt_log_handler)

    for logger_name in ['core', 'gui', 'logic', 'hardware']:
            logging.getLogger(logger_name).setLevel(logging.DEBUG)


# global variables used by exception handler
项目:cligraphy    作者:Netflix-Skunkworks    | 项目源码 | 文件源码
def setup_logging(level=None):
    """Configure logging"""
    logging.addLevelName(DRYRUN_num, DRYRUN_name)
    logging.Logger.dryrun = _dryrun
    try:
        logging.config.dictConfig(_get_dict_config())
        logging.captureWarnings(True)
        silence_verbose_loggers()
        if level is not None:
            logging.getLogger().setLevel(level)
    except Exception:  # pylint:disable=broad-except
        logging.basicConfig(level=logging.WARN)
        logging.warn('Could not configure logging, using basicConfig', exc_info=True)
项目:bonobo    作者:python-bonobo    | 项目源码 | 文件源码
def setup(level):
    logging.addLevelName(DEBUG, 'DEBG')
    logging.addLevelName(INFO, 'INFO')
    logging.addLevelName(WARNING, 'WARN')
    logging.addLevelName(ERROR, 'ERR ')
    logging.addLevelName(CRITICAL, 'CRIT')
    handler = logging.StreamHandler(sys.stderr)
    handler.setFormatter(Formatter(format))
    handler.addFilter(Filter())
    root = logging.getLogger()
    root.addHandler(handler)
    root.setLevel(level)
项目:pefile.pypy    作者:cloudtracer    | 项目源码 | 文件源码
def setUp(self):
        BaseTest.setUp(self)
        for k, v in my_logging_levels.items():
            logging.addLevelName(k, v)
项目:ouroboros    作者:pybee    | 项目源码 | 文件源码
def setUp(self):
        BaseTest.setUp(self)
        for k, v in my_logging_levels.items():
            logging.addLevelName(k, v)
项目:ndk-python    作者:gittor    | 项目源码 | 文件源码
def get_logger():
    '''
    Returns logger used by multiprocessing
    '''
    global _logger
    import logging, atexit

    logging._acquireLock()
    try:
        if not _logger:

            _logger = logging.getLogger(LOGGER_NAME)
            _logger.propagate = 0
            logging.addLevelName(SUBDEBUG, 'SUBDEBUG')
            logging.addLevelName(SUBWARNING, 'SUBWARNING')

            # XXX multiprocessing should cleanup before logging
            if hasattr(atexit, 'unregister'):
                atexit.unregister(_exit_function)
                atexit.register(_exit_function)
            else:
                atexit._exithandlers.remove((_exit_function, (), {}))
                atexit._exithandlers.append((_exit_function, (), {}))

    finally:
        logging._releaseLock()

    return _logger
项目:ndk-python    作者:gittor    | 项目源码 | 文件源码
def setUp(self):
        BaseTest.setUp(self)
        for k, v in my_logging_levels.items():
            logging.addLevelName(k, v)
项目:drc-sim    作者:rolandoislas    | 项目源码 | 文件源码
def __init__(self, name=None):
        if not Logger.console_handler or not Logger.file_handler:
            Logger.logger, Logger.console_handler, Logger.file_handler = self.create_logger(name)
        # Level names
        logging.addLevelName(Logger.EXTRA, "EXTRA")
        logging.addLevelName(Logger.FINER, "FINER")
        logging.addLevelName(Logger.VERBOSE, "VERBOSE")
项目:empyrion-python-api    作者:huhlig    | 项目源码 | 文件源码
def get_logger():
    '''
    Returns logger used by multiprocessing
    '''
    global _logger
    import logging, atexit

    logging._acquireLock()
    try:
        if not _logger:

            _logger = logging.getLogger(LOGGER_NAME)
            _logger.propagate = 0
            logging.addLevelName(SUBDEBUG, 'SUBDEBUG')
            logging.addLevelName(SUBWARNING, 'SUBWARNING')

            # XXX multiprocessing should cleanup before logging
            if hasattr(atexit, 'unregister'):
                atexit.unregister(_exit_function)
                atexit.register(_exit_function)
            else:
                atexit._exithandlers.remove((_exit_function, (), {}))
                atexit._exithandlers.append((_exit_function, (), {}))

    finally:
        logging._releaseLock()

    return _logger
项目:insights-core    作者:RedHatInsights    | 项目源码 | 文件源码
def _start_logging(self, filename):
        #will get the logging instance going
        loglevel_config = 'logging.%s' % self.loglevel

        #i'd like the stdout to be under another logging name than 'con_out'
        console_log_level = 25  #between INFO and WARNING
        quiet = self.quiet
        logging.addLevelName(console_log_level, "CONSOLE")

        def con_out(self, message, *args, **kws):
            if not quiet:
                self._log(console_log_level, message, args, **kws)

        logging.Logger.con_out = con_out

        logging.basicConfig(filename=filename,
            level=eval(loglevel_config),
            format='%(asctime)s %(name)s %(levelname)s: %(message)s',
            datefmt = '%m-%d %H:%M:%S'
            )
        if not self.quiet: # pragma: no cover
            console = logging.StreamHandler(sys.stdout)
            formatter = logging.Formatter('%(asctime)s %(name)s %(levelname)s: %(message)s', '%m-%d %H:%M:%S')
            console.setFormatter(formatter)
            console.setLevel(console_log_level)
    self.logger = logging.getLogger(__name__)
        if not self.quiet:
            self.logger.addHandler(console) # pragma: no cover

        self.logger.con_out("Log File Created at %s" % filename)
项目:pythonista-scripts    作者:khilnani    | 项目源码 | 文件源码
def setup_logging(log_level='INFO'):
    log_format = "%(message)s"
    logging.addLevelName(15, 'FINE')
    logging.basicConfig(format=log_format, level=log_level)