當前位置: 首頁>>代碼示例>>Python>>正文


Python RainbowLoggingHandler.setFormatter方法代碼示例

本文整理匯總了Python中rainbow_logging_handler.RainbowLoggingHandler.setFormatter方法的典型用法代碼示例。如果您正苦於以下問題:Python RainbowLoggingHandler.setFormatter方法的具體用法?Python RainbowLoggingHandler.setFormatter怎麽用?Python RainbowLoggingHandler.setFormatter使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在rainbow_logging_handler.RainbowLoggingHandler的用法示例。


在下文中一共展示了RainbowLoggingHandler.setFormatter方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: setup_logging

# 需要導入模塊: from rainbow_logging_handler import RainbowLoggingHandler [as 別名]
# 或者: from rainbow_logging_handler.RainbowLoggingHandler import setFormatter [as 別名]
def setup_logging() -> None:
    """
    Sets up the logging module to have a verbose option and formats the Console handler and File handler
    """
    logging.addLevelName(VERBOSE, "VERBOSE")
    logging.Logger.verbose = logger_verbose
    logging.verbose = logging_verbose
    logging.VERBOSE = VERBOSE

    # define console handler
    console_handler = ConsoleHandler(sys.stderr)
    if hasattr(console_handler, "_column_color"):
        # noinspection PyProtectedMember
        # pylint: disable=protected-access
        console_handler._column_color['%(message)s'][logging.VERBOSE] = ('cyan', None, False)

    console_formatter = logging.Formatter("[%(asctime)s] %(levelname)s : %(message)s", "%H:%M:%S")
    console_handler.setFormatter(console_formatter)
    console_handler.setLevel(logging.VERBOSE)

    # define file handler
    if not os.path.exists(os.path.dirname(get_global_conf().getdir("install", "log_file"))):
        os.makedirs(os.path.dirname(get_global_conf().getdir("install", "log_file")))
    file_handler = logging.FileHandler(get_global_conf().getdir("install", "log_file"))

    # add handlers
    logging.getLogger().addHandler(console_handler)
    logging.getLogger().addHandler(file_handler)

    logging.getLogger().setLevel(get_global_conf().getint("install", "log_level"))
開發者ID:AmesianX,項目名稱:bugbase,代碼行數:32,代碼來源:logger.py

示例2: setup_console_logging

# 需要導入模塊: from rainbow_logging_handler import RainbowLoggingHandler [as 別名]
# 或者: from rainbow_logging_handler.RainbowLoggingHandler import setFormatter [as 別名]
def setup_console_logging(log_level=None):
    """Setup console logging.

    Aimed to give easy sane defaults for loggig in command line applications.

    Don't use logging settings from INI, but use hardcoded defaults.
    """

    formatter = logging.Formatter("[%(asctime)s] [%(name)s %(funcName)s] %(message)s")  # same as default

    # setup `RainbowLoggingHandler`
    # and quiet some logs for the test output
    handler = RainbowLoggingHandler(sys.stdout)
    handler.setFormatter(formatter)
    logger = logging.getLogger()
    logger.handlers = [handler]

    env_level = os.environ.get("LOG_LEVEL", "info")
    log_level = log_level or getattr(logging, env_level.upper())
    logger.setLevel(log_level)

    logger = logging.getLogger("requests.packages.urllib3.connectionpool")
    logger.setLevel(logging.ERROR)

    # SQL Alchemy transactions
    logger = logging.getLogger("txn")
    logger.setLevel(logging.ERROR)
開發者ID:arianmaykon,項目名稱:websauna,代碼行數:29,代碼來源:cmdline.py

示例3: setup

# 需要導入模塊: from rainbow_logging_handler import RainbowLoggingHandler [as 別名]
# 或者: from rainbow_logging_handler.RainbowLoggingHandler import setFormatter [as 別名]
def setup():
    formatter = logging.Formatter("[%(asctime)s] %(name)s %(funcName)s():%(lineno)d\t%(message)s")  # same as default

    # setup `RainbowLoggingHandler`
    # and quiet some logs for the test output
    handler = RainbowLoggingHandler(sys.stderr)
    handler.setFormatter(formatter)
    logger = logging.getLogger()
    logger.addHandler(handler)

    if "VERBOSE_TEST" in os.environ:
        logger.setLevel(logging.DEBUG)
    else:
        logger.setLevel(logging.ERROR)

    logger = logging.getLogger("requests.packages.urllib3.connectionpool")
    logger.setLevel(logging.ERROR)

    logger = logging.getLogger("cryptoassets.core.backend.blockio")
    logger.setLevel(logging.DEBUG)

    logger = logging.getLogger("cryptoassets.core.backend.bitcoind")
    logger.setLevel(logging.WARN)

    # SQL Alchemy transactions
    logger = logging.getLogger("txn")
    logger.setLevel(logging.ERROR)
開發者ID:ejakait,項目名稱:bitkoin,代碼行數:29,代碼來源:testlogging.py

示例4: setup_custom_logger

# 需要導入模塊: from rainbow_logging_handler import RainbowLoggingHandler [as 別名]
# 或者: from rainbow_logging_handler.RainbowLoggingHandler import setFormatter [as 別名]
def setup_custom_logger():
    LOG_FILE = 'log/cpa'

    formatter = logging.Formatter("[%(asctime)s] %(threadName)s - %(pathname)s %(funcName)s():%(lineno)d  %(levelname)s \t%(message)s")  # same as default
    # formatter = logging.Formatter('%(asctime)s [%(pathname)s: %(lineno)d] %(levelname)s %(message)s')

    logger = logging.getLogger()
    logger.setLevel(logging.DEBUG)

    file_handler = ParallelTimedRotatingFileHandler(LOG_FILE, when='H')
    file_handler.setFormatter(formatter)
    logger.addHandler(file_handler)

    # console_handler = logging.StreamHandler(sys.stdout)
    # console_handler.formatter = formatter
    # logger.addHandler(console_handler)

    # setup `RainbowLoggingHandler`
    handler = RainbowLoggingHandler(sys.stderr, color_funcName=('black', 'yellow', True))
    handler.setFormatter(formatter)
    logger.addHandler(handler)

    #Add file handler
    handler = TimedRotatingFileHandler(LOG_FILE,
                                       when="h",
                                       interval=1,
                                       backupCount=48)

    # try:
    #     raise RuntimeError("Opa!")
    # except Exception as e:
    #     logger.exception(e)

    return logger
開發者ID:ThinkmanWang,項目名稱:CPATCPServer,代碼行數:36,代碼來源:log.py

示例5: test_format_all_column

# 需要導入模塊: from rainbow_logging_handler import RainbowLoggingHandler [as 別名]
# 或者: from rainbow_logging_handler.RainbowLoggingHandler import setFormatter [as 別名]
def test_format_all_column():
    logger = logging.getLogger('test_logging_format_all_column')
    logger.setLevel(logging.DEBUG)

    formatter = logging.Formatter('''
        name            = '%(name)s'
        levelno         = '%(levelno)s'
        levelname       = '%(levelname)s'
        pathname        = '%(pathname)s'
        filename        = '%(filename)s'
        module          = '%(module)s'
        lineno          = '%(lineno)d'
        funcName        = '%(funcName)s'
        created         = '%(created)f'
        asctime         = '%(asctime)s'
        msecs           = '%(msecs)d'
        relativeCreated = '%(relativeCreated)d'
        thread          = '%(thread)d'
        threadName      = '%(threadName)s'
        process         = '%(process)d'
        message         = '%(message)s'
    ''')

    handler = RainbowLoggingHandler(sys.stderr)
    handler.setFormatter(formatter)
    logger.addHandler(handler)

    logger.debug("debug msg")
開發者ID:GNSASE,項目名稱:auto_ndt,代碼行數:30,代碼來源:test_logging.py

示例6: setup_logging

# 需要導入模塊: from rainbow_logging_handler import RainbowLoggingHandler [as 別名]
# 或者: from rainbow_logging_handler.RainbowLoggingHandler import setFormatter [as 別名]
def setup_logging():
    log = logging.getLogger("")
    handler = RainbowLoggingHandler(sys.stderr)
    handler._column_color['%(asctime)s'] = ('cyan', None, False)
    handler._column_color['%(levelname)-7s'] = ('green', None, False)
    handler._column_color['%(message)s'][logging.INFO] = ('blue', None, False)
    handler.setFormatter(logging.Formatter("%(asctime)s %(levelname)-7s %(name)-15s %(message)s"))
    log.addHandler(handler)
    log.setLevel(logging.INFO)
開發者ID:delfick,項目名稱:cloudcity,代碼行數:11,代碼來源:executor.py

示例7: logger

# 需要導入模塊: from rainbow_logging_handler import RainbowLoggingHandler [as 別名]
# 或者: from rainbow_logging_handler.RainbowLoggingHandler import setFormatter [as 別名]
def logger(config_file):
    CONFIG = configparser.RawConfigParser()

    CONFIG.read(config_file)

    logger_config = CONFIG['logger']

    logger = logging.getLogger(logger_config['name'])

    logger.setLevel(LOGGING_LEVELS.get(logger_config['level'], logging.NOTSET))

    formatter = logging.Formatter(
        '[%(asctime)s] %(name)s %(funcName)s():%(lineno)d\t%(message)s'
    )

    handler = RainbowLoggingHandler(
        sys.stderr,
        color_funcName=('black', 'yellow', True)
    )

    handler.setFormatter(formatter)

    logger.addHandler(handler)

    if CONFIG.has_section('file_logger'):
        file_logger_config = CONFIG['file_logger']

        fh = logging.handlers.RotatingFileHandler(
            file_logger_config['file_path'],
            maxBytes=int(file_logger_config['max_log_file_size']),
            backupCount=int(file_logger_config['backup_count'])
        )

        fh.setLevel(LOGGING_LEVELS.get(file_logger_config['level'],
                                       logging.NOTSET))
        fh.setFormatter(formatter)
        logger.addHandler(fh)

    if CONFIG.has_section('email_logger'):
        email_logger_config = CONFIG['email_logger']

        eh = logging.handlers.SMTPHandler(
            (email_logger_config['host'], email_logger_config['port']),
            email_logger_config['from'],
            email_logger_config['to'],
            email_logger_config['subject'],
            (email_logger_config['username'], email_logger_config['password']),
            ()
        )

        eh.setLevel(LOGGING_LEVELS.get(email_logger_config['level'],
                                       logging.NOTSET))
        eh.setFormatter(formatter)
        logger.addHandler(eh)

    return logger
開發者ID:jvmsangkal,項目名稱:freedom_python_logger,代碼行數:58,代碼來源:__init__.py

示例8: add_stdout_handler

# 需要導入模塊: from rainbow_logging_handler import RainbowLoggingHandler [as 別名]
# 或者: from rainbow_logging_handler.RainbowLoggingHandler import setFormatter [as 別名]
def add_stdout_handler(logger, formatter):
    try:
        from rainbow_logging_handler import RainbowLoggingHandler
        handler = RainbowLoggingHandler(sys.stderr, color_funcName=(
            'black', 'black', True))
    except ImportError:
        handler = logging.StreamHandler()
        pass

    handler.setFormatter(formatter)
    logger.addHandler(handler)
開發者ID:Zopieux,項目名稱:touchandgo,代碼行數:13,代碼來源:logger.py

示例9: setup_logging

# 需要導入模塊: from rainbow_logging_handler import RainbowLoggingHandler [as 別名]
# 或者: from rainbow_logging_handler.RainbowLoggingHandler import setFormatter [as 別名]
def setup_logging(verbose=False):
    log = logging.getLogger("")
    handler = RainbowLoggingHandler(sys.stderr)
    handler._column_color['%(asctime)s'] = ('cyan', None, False)
    handler._column_color['%(levelname)-7s'] = ('green', None, False)
    handler._column_color['%(message)s'][logging.INFO] = ('blue', None, False)
    handler.setFormatter(logging.Formatter("%(asctime)s %(levelname)-7s %(name)-15s %(message)s"))
    log.addHandler(handler)
    log.setLevel([logging.INFO, logging.DEBUG][verbose])

    logging.getLogger("boto").level = logging.CRITICAL
開發者ID:realestate-com-au,項目名稱:iam_syncr,代碼行數:13,代碼來源:executor.py

示例10: test_custom_format

# 需要導入模塊: from rainbow_logging_handler import RainbowLoggingHandler [as 別名]
# 或者: from rainbow_logging_handler.RainbowLoggingHandler import setFormatter [as 別名]
def test_custom_format():
    logger = logging.getLogger('test_logging_custom_format')
    logger.setLevel(logging.DEBUG)
    formatter = logging.Formatter("MESSAGE ONLY => %(message)s")

    handler = RainbowLoggingHandler(sys.stderr)
    handler.setFormatter(formatter)
    logger.addHandler(handler)

    logger.debug("debug msg")
    logger.info("info msg")
    logger.warn("warn msg")
    logger.error("error msg")
    logger.critical("critical msg")
開發者ID:GNSASE,項目名稱:auto_ndt,代碼行數:16,代碼來源:test_logging.py

示例11: setup_logging

# 需要導入模塊: from rainbow_logging_handler import RainbowLoggingHandler [as 別名]
# 或者: from rainbow_logging_handler.RainbowLoggingHandler import setFormatter [as 別名]
def setup_logging(verbose=False, silent=False, debug=False):
    log = logging.getLogger("")
    handler = RainbowLoggingHandler(sys.stderr)
    handler._column_color['%(asctime)s'] = ('cyan', None, False)
    handler._column_color['%(levelname)-7s'] = ('green', None, False)
    handler._column_color['%(message)s'][logging.INFO] = ('blue', None, False)
    handler.setFormatter(logging.Formatter("%(asctime)s %(levelname)-7s %(name)-15s %(message)s"))
    log.addHandler(handler)
    log.setLevel([logging.INFO, logging.DEBUG][verbose or debug])
    if silent:
        log.setLevel(logging.ERROR)

    logging.getLogger("requests").setLevel([logging.CRITICAL, logging.ERROR][verbose or debug])
    return handler
開發者ID:CaseyLeask,項目名稱:harpoon,代碼行數:16,代碼來源:executor.py

示例12: setup

# 需要導入模塊: from rainbow_logging_handler import RainbowLoggingHandler [as 別名]
# 或者: from rainbow_logging_handler.RainbowLoggingHandler import setFormatter [as 別名]
def setup():
    # prepare log file
    global f_log, logpath
    (fd, logpath) = mkstemp(prefix='raibow-', suffix='.txt')
    f_log = os.fdopen(fd, 'w')

    # prepare 'test_format' logger
    logger = logging.getLogger('test_format')
    logger.setLevel(logging.DEBUG)
    formatter = logging.Formatter("AAA %(name)s - %(levelname)s - %(message)s ZZZ")  # testing whether this format is used

    handler = RainbowLoggingHandler(f_log)
    handler.setFormatter(formatter)
    logger.addHandler(handler)
開發者ID:GNSASE,項目名稱:auto_ndt,代碼行數:16,代碼來源:test_format.py

示例13: get_logger

# 需要導入模塊: from rainbow_logging_handler import RainbowLoggingHandler [as 別名]
# 或者: from rainbow_logging_handler.RainbowLoggingHandler import setFormatter [as 別名]
def get_logger():
    global logger
    
    if logger == None:
        logger = logging.getLogger('freesprints')
        logger.setLevel(logging.DEBUG)
        formatter = logging.Formatter("[%(asctime)s] %(name)s %(funcName)s():%(lineno)d\t%(message)s")  # same as default
        
        # setup colored logging
        handler = RainbowLoggingHandler(sys.stderr, color_funcName=('black', 'yellow', True))
        handler.setFormatter(formatter)
        logger.addHandler(handler)
    
    return logger
開發者ID:niklasberglund,項目名稱:freesprints,代碼行數:16,代碼來源:__init__.py

示例14: __init__

# 需要導入模塊: from rainbow_logging_handler import RainbowLoggingHandler [as 別名]
# 或者: from rainbow_logging_handler.RainbowLoggingHandler import setFormatter [as 別名]
    def __init__(self, module_name):
        self.logger_tmp = None
        logger = logging.getLogger(module_name)
        logging.basicConfig(filename='/tmp/r2als.log',level=logging.DEBUG,format='%(asctime)s %(levelname)s %(message)s')
        # logging.basicConfig(level=logging.DEBUG)
        formatter = logging.Formatter("[%(asctime)s] %(name)s %(funcName)s():%(lineno)d\t%(message)s")  # same as default

         # setup `RainbowLoggingHandler`
        handler = RainbowLoggingHandler(sys.stderr, color_funcName=('black', 'gray', True))
        handler.setFormatter(formatter)

        logger.addHandler(handler)

        self.logger_tmp = logger
開發者ID:mildronize,項目名稱:R2ALS,代碼行數:16,代碼來源:logs.py

示例15: setup_logging

# 需要導入模塊: from rainbow_logging_handler import RainbowLoggingHandler [as 別名]
# 或者: from rainbow_logging_handler.RainbowLoggingHandler import setFormatter [as 別名]
    def setup_logging(self, args, verbose=False, silent=False, debug=False, logging_name=""):
        """Setup the RainbowLoggingHandler for the logs and call setup_other_logging"""
        log = logging.getLogger(logging_name)
        handler = RainbowLoggingHandler(self.logging_handler_file)
        handler._column_color['%(asctime)s'] = ('cyan', None, False)
        handler._column_color['%(levelname)-7s'] = ('green', None, False)
        handler._column_color['%(message)s'][logging.INFO] = ('blue', None, False)
        handler.setFormatter(logging.Formatter("%(asctime)s %(levelname)-7s %(name)-15s %(message)s"))
        log.addHandler(handler)
        log.setLevel([logging.INFO, logging.DEBUG][verbose or debug])
        if silent:
            log.setLevel(logging.ERROR)

        self.setup_other_logging(args, verbose, silent, debug)
        return handler
開發者ID:jonhiggs,項目名稱:delfick_app,代碼行數:17,代碼來源:delfick_app.py


注:本文中的rainbow_logging_handler.RainbowLoggingHandler.setFormatter方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。