本文整理汇总了Python中logging.PlaceHolder方法的典型用法代码示例。如果您正苦于以下问题:Python logging.PlaceHolder方法的具体用法?Python logging.PlaceHolder怎么用?Python logging.PlaceHolder使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类logging
的用法示例。
在下文中一共展示了logging.PlaceHolder方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: set_logger_levels
# 需要导入模块: import logging [as 别名]
# 或者: from logging import PlaceHolder [as 别名]
def set_logger_levels(debug=False):
"""Set all of the logger levels
Args:
debug (bool): True to enable debug logging, False otherwise
"""
for name, logger in logging.Logger.manager.loggerDict.items():
if isinstance(logger, logging.PlaceHolder):
continue
if debug and name.startswith('streamalert'):
logger.setLevel(logging.DEBUG if debug else logging.INFO)
elif name.startswith(__package__):
logger.setLevel(logging.INFO)
else:
logger.disabled = True # disable this logger if it's not one of ours
示例2: _handle_existing_loggers
# 需要导入模块: import logging [as 别名]
# 或者: from logging import PlaceHolder [as 别名]
def _handle_existing_loggers(existing, child_loggers, disable_existing):
"""
When (re)configuring logging, handle loggers which were in the previous
configuration but are not in the new configuration. There's no point
deleting them as other threads may continue to hold references to them;
and by disabling them, you stop them doing any logging.
However, don't disable children of named loggers, as that's probably not
what was intended by the user. Also, allow existing loggers to NOT be
disabled if disable_existing is false.
"""
root = logging.root
for log in existing:
logger = root.manager.loggerDict[log]
if log in child_loggers:
if not isinstance(logger, logging.PlaceHolder):
logger.setLevel(logging.NOTSET)
logger.handlers = []
logger.propagate = True
else:
logger.disabled = disable_existing
示例3: setOverrideLogLevel
# 需要导入模块: import logging [as 别名]
# 或者: from logging import PlaceHolder [as 别名]
def setOverrideLogLevel(lvl):
"""
Override all logger filter levels to include lvl and above.
- Set root logger level
- iterates all existing loggers and sets their log level to ``NOTSET``.
Args:
lvl (string): Log level name.
"""
if lvl is None:
return
logging.info('Overriding log level globally to %s', lvl)
lvl = getLevelName(lvl)
global _overrideLogLevel # pylint: disable=global-statement
_overrideLogLevel = lvl
logging.getLogger('').setLevel(lvl)
for loggerName in logging.Logger.manager.loggerDict:
logger = logging.Logger.manager.loggerDict[loggerName]
if isinstance(logger, logging.PlaceHolder):
continue
logger.setLevel(logging.NOTSET)
示例4: __build_ref_lists
# 需要导入模块: import logging [as 别名]
# 或者: from logging import PlaceHolder [as 别名]
def __build_ref_lists(self):
"""
Build up easy-to-use lists of loggers and handlers.
"""
ll = {}
hl = {}
loggers = dict(logging.Logger.manager.loggerDict)
loggers[''] = logging.getLogger('')
loggers['root'] = logging.getLogger('')
for lg_name, lg_obj in loggers.items():
if not isinstance(lg_obj, logging.PlaceHolder):
ll[lg_name] = lg_obj
for handler in lg_obj.handlers:
hl[handler.get_name()] = handler
self.__loggers_by_name = ll
self.__handlers_by_name = hl
示例5: print_all_logging_handlers
# 需要导入模块: import logging [as 别名]
# 或者: from logging import PlaceHolder [as 别名]
def print_all_logging_handlers():
for k, v in logging.Logger.manager.loggerDict.items():
print("+ [%s] {%s} " % (str.ljust(k, 20), str(v.__class__)[8:-2]))
if not isinstance(v, logging.PlaceHolder):
for h in v.handlers:
print(" +++", str(h.__class__)[8:-2])
示例6: configure
# 需要导入模块: import logging [as 别名]
# 或者: from logging import PlaceHolder [as 别名]
def configure(config_string=None, log_json=False, log_file=None):
if not config_string:
config_string = ":{}".format(DEFAULT_LOGLEVEL)
if log_json:
SLogger.manager.log_json = True
log_format = JSON_FORMAT
else:
SLogger.manager.log_json = False
log_format = PRINT_FORMAT
if len(rootLogger.handlers) == 0:
#handler = StreamHandler()
handler = StreamHandler(sys.stdout)
#formatter = Formatter(log_format)
formatter = QKCLogFormatter()
handler.setFormatter(formatter)
rootLogger.addHandler(handler)
if log_file:
if not any(isinstance(hndlr, FileHandler)
for hndlr in rootLogger.handlers):
handler = FileHandler(log_file)
formatter = Formatter("{} {}".format(FILE_PREFIX, log_format))
handler.setFormatter(formatter)
rootLogger.addHandler(handler)
# Reset logging levels before applying new config below
for name, logger in SLogger.manager.loggerDict.items():
if hasattr(logger, 'setLevel'):
# Guard against `logging.PlaceHolder` instances
logger.setLevel(logging.NOTSET)
if config_string == ":{}".format(DEFAULT_LOGLEVEL):
logger.propagate = True
else:
logger.propagate = True
for name_levels in config_string.split(','):
name, _, level = name_levels.partition(':')
logger = getLogger(name)
logger.setLevel(level.upper())
logger.propagate = True
示例7: _iter_loggers
# 需要导入模块: import logging [as 别名]
# 或者: from logging import PlaceHolder [as 别名]
def _iter_loggers():
"""Iterate on existing loggers."""
# Sadly, Logger.manager and Manager.loggerDict are not documented,
# but there is no logging public function to iterate on all loggers.
# The root logger is not part of loggerDict.
yield logging.getLogger()
manager = logging.Logger.manager
for logger in manager.loggerDict.values():
if isinstance(logger, logging.PlaceHolder):
continue
yield logger
示例8: terminate
# 需要导入模块: import logging [as 别名]
# 或者: from logging import PlaceHolder [as 别名]
def terminate():
for _, logger in logging.Logger.manager.loggerDict.items():
if isinstance(logger, logging.PlaceHolder):
continue
for handler in logger.handlers:
if isinstance(handler, logging.FileHandler):
handler.close()
# TODO: These are suboptimal as they getLogger each time. Any real performance hit here?
# TODO: Consider finding all newlines in the msg and ensuring the log prefix is added for each
# newline. Would improve formatting for certain stuff.
示例9: update_loggers
# 需要导入模块: import logging [as 别名]
# 或者: from logging import PlaceHolder [as 别名]
def update_loggers(self):
loggers = deepcopy(self._config.get('loggers') or {})
for name, logger in self._root_logger.manager.loggerDict.items():
if not isinstance(logger, logging.PlaceHolder):
level = loggers.pop(name, logging.NOTSET)
logger.setLevel(level)
for name, level in loggers.items():
logger = self._root_logger.manager.getLogger(name)
logger.setLevel(level)
示例10: __recurse_list
# 需要导入模块: import logging [as 别名]
# 或者: from logging import PlaceHolder [as 别名]
def __recurse_list(self, indent, logger, detail):
"""
Print the passed in logger, its handlers, and then recurse on other
loggers under its space.
"""
indent_txt = ' ' * indent
print >>sys.stderr, 'L{0}{1}: level={2}'.format(indent_txt, logger.name, logger.level)
for handler in logger.handlers:
self.__display_handler(indent + 1, handler, detail)
for lg_name, lg_obj in logging.Logger.manager.loggerDict.items():
if isinstance(lg_obj, logging.PlaceHolder):
continue
if lg_obj.parent == logger:
self.__recurse_list(indent + 3, lg_obj, detail)
示例11: initLogging
# 需要导入模块: import logging [as 别名]
# 或者: from logging import PlaceHolder [as 别名]
def initLogging(logLevel=logging.INFO):
global LOGGING_INITIALIZED
if LOGGING_INITIALIZED:
print("ERROR - Logging initialized twice!")
try:
print(traceback.format_exc())
return
except Exception:
pass
LOGGING_INITIALIZED = True
print("Setting up loggers....")
if not os.path.exists(os.path.join("./logs")):
os.mkdir(os.path.join("./logs"))
mainLogger = logging.getLogger() # Main logger
mainLogger.setLevel(logLevel)
ch = ColourHandler()
mainLogger.addHandler(ch)
logName = "log - %s.txt" % (time.strftime("%Y-%m-%d %H;%M;%S", time.gmtime()))
errLogHandler = RobustFileHandler(os.path.join("./logs", logName))
errLogHandler.setLevel(logging.INFO)
# formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
# errLogHandler.setFormatter(formatter)
# mainLogger.addHandler(errLogHandler)
# Install override for excepthook, to catch all errors
sys.excepthook = exceptHook
logtst = logging.getLogger("Main.Test")
logtst.info("Logging Active")
print("done")
# print("Enumerating loggers:")
# for k,v in logging.Logger.manager.loggerDict.items() :
# print('+ [%s] {%s} ' % (str.ljust( k, 20) , str(v.__class__)[8:-2]) )
# if not isinstance(v, logging.PlaceHolder):
# for h in v.handlers:
# print(' +++',str(h.__class__)[8:-2] )
# print("Done listing")