本文整理汇总了Python中logging.level方法的典型用法代码示例。如果您正苦于以下问题:Python logging.level方法的具体用法?Python logging.level怎么用?Python logging.level使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类logging
的用法示例。
在下文中一共展示了logging.level方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: set_logger
# 需要导入模块: import logging [as 别名]
# 或者: from logging import level [as 别名]
def set_logger():
logging.level = logging.DEBUG
logFormatter = \
logging.Formatter("%(asctime)s %(levelname)s %(message)s")
rootLogger = logging.getLogger()
rootLogger.setLevel(logging.DEBUG)
logfile = '/tmp/ansibullbot.log'
fileHandler = logging.FileHandler("{0}/{1}".format(
os.path.dirname(logfile),
os.path.basename(logfile))
)
fileHandler.setFormatter(logFormatter)
rootLogger.addHandler(fileHandler)
consoleHandler = logging.StreamHandler()
consoleHandler.setFormatter(logFormatter)
rootLogger.addHandler(consoleHandler)
示例2: convert_level
# 需要导入模块: import logging [as 别名]
# 或者: from logging import level [as 别名]
def convert_level(level):
if not level:
return None
_valid_levels = [
logging.DEBUG,
logging.INFO,
logging.WARNING,
logging.ERROR,
logging.CRITICAL,
]
if level in _valid_levels:
return level
if level.lower() == "info":
return logging.INFO
elif level.lower() == "debug":
return logging.DEBUG
elif level.lower() == "warning":
return logging.WARNING
elif level.lower() == "error":
return logging.ERROR
elif level.lower() == "critical":
return logging.CRITICAL
raise ValueError(
"Wrong log level use one of the following : {}".format(_valid_levels)
)
示例3: create_logger
# 需要导入模块: import logging [as 别名]
# 或者: from logging import level [as 别名]
def create_logger(name, level=logging.INFO):
"""Get the Strawberry Fields module specific logger and configure it if needed.
Configuration only takes place if no user configuration was applied to the
logger. Therefore, the logger is configured if and only if the following
are true:
- the logger has WARNING as effective level,
- the level of the logger was not explicitly set,
- no handlers were added to the logger.
As the root logger has a WARNING level by default, any module specific
logger will inherit the same as effective level.
The default handler that is used for configuration writes to the standard
error stream and uses a datetime and level formatter.
Args:
name (str): the name of the module for which the logger is being created
level (logging.level): the logging level to set for the logger
"""
logger = logging.getLogger(name)
effective_level_inherited = logger.getEffectiveLevel() == logging.WARNING
level_not_set = not logger.level
no_handlers = not logging_handler_defined(logger)
if effective_level_inherited and level_not_set and no_handlers:
logger.setLevel(level)
logger.addHandler(default_handler)
return logger
示例4: set_log_level
# 需要导入模块: import logging [as 别名]
# 或者: from logging import level [as 别名]
def set_log_level(level, handler=None):
""" Set both vspk and Bambou log level to the given level
Args:
level (logging.level): a logging level
handler (logging.Handler): a logging handler
Notes:
if no handler is provided, it will automatically create a new StreamHandler.
Examples:
>>> set_log_level(logging.INFO)
>>> set_log_level(logging.DEBUG, logging.Streamhandler())
>>> set_log_level(logging.ERROR)
"""
from bambou import bambou_logger, pushcenter_logger
if handler is None:
handler = logging.StreamHandler()
bambou_logger.setLevel(level)
bambou_logger.addHandler(handler)
pushcenter_logger.setLevel(level)
pushcenter_logger.addHandler(handler)
logger.setLevel(level)
logger.addHandler(handler)
示例5: set_logger
# 需要导入模块: import logging [as 别名]
# 或者: from logging import level [as 别名]
def set_logger(debug=False, logfile=None):
logFormatter = \
logging.Formatter("%(asctime)s %(levelname)s %(process)d %(filename)s:%(funcName)s:%(lineno)d %(message)s")
rootLogger = logging.getLogger()
if debug:
logging.level = logging.DEBUG
rootLogger.setLevel(logging.DEBUG)
else:
logging.level = logging.INFO
rootLogger.setLevel(logging.INFO)
if logfile:
try:
logdir = os.path.dirname(logfile)
if logdir and not os.path.isdir(logdir):
os.makedirs(logdir)
fileHandler = WatchedFileHandler(logfile)
fileHandler.setFormatter(logFormatter)
rootLogger.addHandler(fileHandler)
except Exception as e:
pass
consoleHandler = logging.StreamHandler()
consoleHandler.setFormatter(logFormatter)
rootLogger.addHandler(consoleHandler)
示例6: set_logger
# 需要导入模块: import logging [as 别名]
# 或者: from logging import level [as 别名]
def set_logger():
logging.level = logging.DEBUG
logFormatter = \
logging.Formatter("%(asctime)s %(levelname)s %(message)s")
rootLogger = logging.getLogger()
rootLogger.setLevel(logging.DEBUG)
consoleHandler = logging.StreamHandler()
consoleHandler.setFormatter(logFormatter)
rootLogger.addHandler(consoleHandler)
示例7: main
# 需要导入模块: import logging [as 别名]
# 或者: from logging import level [as 别名]
def main():
logging.level = logging.DEBUG
logFormatter = logging.Formatter("%(asctime)s %(levelname)s %(message)s")
rootLogger = logging.getLogger()
rootLogger.setLevel(logging.DEBUG)
consoleHandler = logging.StreamHandler()
consoleHandler.setFormatter(logFormatter)
rootLogger.addHandler(consoleHandler)
scraper = Scraper()
示例8: __init__
# 需要导入模块: import logging [as 别名]
# 或者: from logging import level [as 别名]
def __init__(self, name=None):
self.logger = logging.getLogger(name or self.Default_Name)
self.level = logging.DEBUG if self.config.getboolean("Base", "debug") else logging.INFO
self.logger.setLevel(self.level)
self.add_handler(self.console_headler)
示例9: console_headler
# 需要导入模块: import logging [as 别名]
# 或者: from logging import level [as 别名]
def console_headler(self):
console_headler = logging.StreamHandler(sys.stdout)
console_headler.setLevel(self.level)
console_headler.setFormatter(self.format)
return console_headler
示例10: __init__
# 需要导入模块: import logging [as 别名]
# 或者: from logging import level [as 别名]
def __init__(self,
level,
named_levels=None,
format_string=None,
additional_fields=None):
self.level = level
# Any false values passed for named_levels should instead be treated as
# an empty dictionary i.e. no special log levels
self.named_levels = named_levels or {}
# Any false values for format string should use the default instead
self.format_string = format_string or LoggingConfig._default_log_format
self.additional_fields = additional_fields
示例11: setup_logging
# 需要导入模块: import logging [as 别名]
# 或者: from logging import level [as 别名]
def setup_logging(self):
""" Establishes the base logging using the appropriate filter
attached to the console/stream handler.
"""
console_handler = logging.StreamHandler()
request_logging.assign_request_filter(console_handler,
self.additional_fields)
logging.basicConfig(level=self.level,
format=self.format_string,
handlers=[console_handler])
for handler in logging.root.handlers:
handler.setFormatter(RedactionFormatter(handler.formatter))
logger = logging.getLogger(__name__)
logger.info('Established logging defaults')
self._setup_log_levels()
示例12: _setup_log_levels
# 需要导入模块: import logging [as 别名]
# 或者: from logging import level [as 别名]
def _setup_log_levels(self):
"""Sets up the logger levels for named loggers
:param named_levels: dict to set each of the specified
logging levels.
"""
for logger_name, level in self.named_levels.items():
logger = logging.getLogger(logger_name)
logger.setLevel(level)
LOG.info("Set %s to use logging level %s", logger_name, level)