本文整理汇总了Python中logging.LEVEL属性的典型用法代码示例。如果您正苦于以下问题:Python logging.LEVEL属性的具体用法?Python logging.LEVEL怎么用?Python logging.LEVEL使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类logging
的用法示例。
在下文中一共展示了logging.LEVEL属性的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: set_file_logger
# 需要导入模块: import logging [as 别名]
# 或者: from logging import LEVEL [as 别名]
def set_file_logger(filename, name='funcx', level=logging.DEBUG, format_string=None):
"""Add a stream log handler.
Args:
- filename (string): Name of the file to write logs to
- name (string): Logger name
- level (logging.LEVEL): Set the logging level.
- format_string (string): Set the format string
Returns:
- None
"""
if format_string is None:
format_string = "%(asctime)s.%(msecs)03d %(name)s:%(lineno)d [%(levelname)s] %(message)s"
logger = logging.getLogger(name)
logger.setLevel(logging.DEBUG)
handler = logging.FileHandler(filename)
handler.setLevel(level)
formatter = logging.Formatter(format_string, datefmt='%Y-%m-%d %H:%M:%S')
handler.setFormatter(formatter)
logger.addHandler(handler)
return logger
示例2: set_stream_logger
# 需要导入模块: import logging [as 别名]
# 或者: from logging import LEVEL [as 别名]
def set_stream_logger(name='funcx', level=logging.DEBUG, format_string=None):
"""Add a stream log handler.
Args:
- name (string) : Set the logger name.
- level (logging.LEVEL) : Set to logging.DEBUG by default.
- format_string (string) : Set to None by default.
Returns:
- None
"""
if format_string is None:
# format_string = "%(asctime)s %(name)s [%(levelname)s] Thread:%(thread)d %(message)s"
format_string = "%(asctime)s %(name)s:%(lineno)d [%(levelname)s] %(message)s"
logger = logging.getLogger(name)
logger.setLevel(logging.DEBUG)
handler = logging.StreamHandler()
handler.setLevel(level)
formatter = logging.Formatter(format_string, datefmt='%Y-%m-%d %H:%M:%S')
handler.setFormatter(formatter)
logger.addHandler(handler)
return logger
示例3: start_file_logger
# 需要导入模块: import logging [as 别名]
# 或者: from logging import LEVEL [as 别名]
def start_file_logger(filename, rank, name='parsl', level=logging.DEBUG, format_string=None):
"""Add a stream log handler.
Args:
- filename (string): Name of the file to write logs to
- name (string): Logger name
- level (logging.LEVEL): Set the logging level.
- format_string (string): Set the format string
Returns:
- None
"""
if format_string is None:
format_string = "%(asctime)s.%(msecs)03d %(name)s:%(lineno)d Rank:{0} [%(levelname)s] %(message)s".format(rank)
global logger
logger = logging.getLogger(name)
logger.setLevel(logging.DEBUG)
handler = logging.FileHandler(filename)
handler.setLevel(level)
formatter = logging.Formatter(format_string, datefmt='%Y-%m-%d %H:%M:%S')
handler.setFormatter(formatter)
logger.addHandler(handler)
示例4: set_stream_logger
# 需要导入模块: import logging [as 别名]
# 或者: from logging import LEVEL [as 别名]
def set_stream_logger(name='parsl', level=logging.DEBUG, format_string=None):
"""Add a stream log handler.
Args:
- name (string) : Set the logger name.
- level (logging.LEVEL) : Set to logging.DEBUG by default.
- format_string (sting) : Set to None by default.
Returns:
- None
"""
if format_string is None:
format_string = "%(asctime)s %(name)s [%(levelname)s] Thread:%(thread)d %(message)s"
# format_string = "%(asctime)s %(name)s:%(lineno)d [%(levelname)s] %(message)s"
global logger
logger = logging.getLogger(name)
logger.setLevel(logging.DEBUG)
handler = logging.StreamHandler()
handler.setLevel(level)
formatter = logging.Formatter(format_string, datefmt='%Y-%m-%d %H:%M:%S')
handler.setFormatter(formatter)
logger.addHandler(handler)
示例5: start_file_logger
# 需要导入模块: import logging [as 别名]
# 或者: from logging import LEVEL [as 别名]
def start_file_logger(filename, name="interchange", level=logging.DEBUG, format_string=None):
"""Add a stream log handler.
Parameters
---------
filename: string
Name of the file to write logs to. Required.
name: string
Logger name. Default="parsl.executors.interchange"
level: logging.LEVEL
Set the logging level. Default=logging.DEBUG
- format_string (string): Set the format string
format_string: string
Format string to use.
Returns
-------
None.
"""
if format_string is None:
format_string = "%(asctime)s.%(msecs)03d %(name)s:%(lineno)d [%(levelname)s] %(message)s"
global logger
logger = logging.getLogger(name)
logger.setLevel(level)
if not len(logger.handlers):
handler = logging.FileHandler(filename)
handler.setLevel(level)
formatter = logging.Formatter(format_string, datefmt='%Y-%m-%d %H:%M:%S')
handler.setFormatter(formatter)
logger.addHandler(handler)
示例6: init
# 需要导入模块: import logging [as 别名]
# 或者: from logging import LEVEL [as 别名]
def init(base_level=DEFAULT_BASE_LOGGING_LEVEL,
verbose_level=DEFAULT_VERBOSE_LOGGING_LEVEL,
logging_config=None):
"""initializes a base logger
you can use this to init a logger in any of your files.
this will use config.py's LOGGER param and logging.dictConfig to configure
the logger for you.
:param int|logging.LEVEL base_level: desired base logging level
:param int|logging.LEVEL verbose_level: desired verbose logging level
:param dict logging_dict: dictConfig based configuration.
used to override the default configuration from config.py
:rtype: `python logger`
"""
if logging_config is None:
logging_config = {}
logging_config = logging_config or LOGGER
# TODO: (IMPRV) only perform file related actions if file handler is
# TODO: (IMPRV) defined.
log_file = LOGGER['handlers']['file']['filename']
log_dir = os.path.dirname(os.path.expanduser(log_file))
if os.path.isfile(log_dir):
sys.exit('file {0} exists - log directory cannot be created '
'there. please remove the file and try again.'
.format(log_dir))
try:
if not os.path.exists(log_dir) and not len(log_dir) == 0:
os.makedirs(log_dir)
dictconfig.dictConfig(logging_config)
lgr = logging.getLogger('user')
lgr.setLevel(base_level)
return lgr
except ValueError as e:
sys.exit('could not initialize logger.'
' verify your logger config'
' and permissions to write to {0} ({1})'
.format(log_file, e))
示例7: _init_logging
# 需要导入模块: import logging [as 别名]
# 或者: from logging import LEVEL [as 别名]
def _init_logging(level: str = 'INFO'):
""""
Initializes the Python logging
Parameters:
level (int): Optional - The level to which the logger will be initialized.
Use any of the available logging.LEVEL values.
If not specified, the default level will be set to logging.INFO
"""
logging.basicConfig(format='%(asctime)s - %(levelname)s - %(funcName)s - %(message)s',
level=level)
示例8: start_file_logger
# 需要导入模块: import logging [as 别名]
# 或者: from logging import LEVEL [as 别名]
def start_file_logger(filename, name='monitoring', level=logging.DEBUG, format_string=None):
"""Add a stream log handler.
Parameters
---------
filename: string
Name of the file to write logs to. Required.
name: string
Logger name.
level: logging.LEVEL
Set the logging level. Default=logging.DEBUG
- format_string (string): Set the format string
format_string: string
Format string to use.
Returns
-------
None.
"""
if format_string is None:
format_string = "%(asctime)s.%(msecs)03d %(name)s:%(lineno)d [%(levelname)s] %(message)s"
logger = logging.getLogger(name)
logger.setLevel(level)
handler = logging.FileHandler(filename)
handler.setLevel(level)
formatter = logging.Formatter(format_string, datefmt='%Y-%m-%d %H:%M:%S')
handler.setFormatter(formatter)
logger.addHandler(handler)
return logger
示例9: set_stream_logger
# 需要导入模块: import logging [as 别名]
# 或者: from logging import LEVEL [as 别名]
def set_stream_logger(name: str = 'parsl', level: int = logging.DEBUG, format_string: Optional[str] = None):
"""Add a stream log handler.
Args:
- name (string) : Set the logger name.
- level (logging.LEVEL) : Set to logging.DEBUG by default.
- format_string (string) : Set to None by default.
Returns:
- None
"""
if format_string is None:
# format_string = "%(asctime)s %(name)s [%(levelname)s] Thread:%(thread)d %(message)s"
format_string = "%(asctime)s %(name)s:%(lineno)d [%(levelname)s] %(message)s"
logger = logging.getLogger(name)
logger.setLevel(logging.DEBUG)
handler = logging.StreamHandler()
handler.setLevel(level)
formatter = logging.Formatter(format_string, datefmt='%Y-%m-%d %H:%M:%S')
handler.setFormatter(formatter)
logger.addHandler(handler)
# Concurrent.futures errors are also of interest, as exceptions
# which propagate out of the top of a callback are logged this way
# and then discarded. (see #240)
futures_logger = logging.getLogger("concurrent.futures")
futures_logger.addHandler(handler)
示例10: set_file_logger
# 需要导入模块: import logging [as 别名]
# 或者: from logging import LEVEL [as 别名]
def set_file_logger(filename: str, name: str = 'parsl', level: int = logging.DEBUG, format_string: Optional[str] = None):
"""Add a stream log handler.
Args:
- filename (string): Name of the file to write logs to
- name (string): Logger name
- level (logging.LEVEL): Set the logging level.
- format_string (string): Set the format string
Returns:
- None
"""
if format_string is None:
format_string = "%(asctime)s.%(msecs)03d %(name)s:%(lineno)d [%(levelname)s] %(message)s"
logger = logging.getLogger(name)
logger.setLevel(logging.DEBUG)
handler = logging.FileHandler(filename)
handler.setLevel(level)
formatter = logging.Formatter(format_string, datefmt='%Y-%m-%d %H:%M:%S')
handler.setFormatter(formatter)
logger.addHandler(handler)
# see note in set_stream_logger for notes about logging
# concurrent.futures
futures_logger = logging.getLogger("concurrent.futures")
futures_logger.addHandler(handler)
示例11: start_file_logger
# 需要导入模块: import logging [as 别名]
# 或者: from logging import LEVEL [as 别名]
def start_file_logger(filename, name='interchange', level=logging.DEBUG, format_string=None):
"""Add a stream log handler.
Parameters
---------
filename: string
Name of the file to write logs to. Required.
name: string
Logger name. Default="parsl.executors.interchange"
level: logging.LEVEL
Set the logging level. Default=logging.DEBUG
- format_string (string): Set the format string
format_string: string
Format string to use.
Returns
-------
None.
"""
if format_string is None:
format_string = "%(asctime)s %(name)s:%(lineno)d [%(levelname)s] %(message)s"
global logger
logger = logging.getLogger(name)
logger.setLevel(level)
handler = logging.FileHandler(filename)
handler.setLevel(level)
formatter = logging.Formatter(format_string, datefmt='%Y-%m-%d %H:%M:%S')
handler.setFormatter(formatter)
logger.addHandler(handler)
示例12: start_file_logger
# 需要导入模块: import logging [as 别名]
# 或者: from logging import LEVEL [as 别名]
def start_file_logger(filename, rank, name='parsl', level=logging.DEBUG, format_string=None):
"""Add a stream log handler.
Args:
- filename (string): Name of the file to write logs to
- name (string): Logger name
- level (logging.LEVEL): Set the logging level.
- format_string (string): Set the format string
Returns:
- None
"""
try:
os.makedirs(os.path.dirname(filename), 511, True)
except Exception as e:
print("Caught exception with trying to make log dirs: {}".format(e))
if format_string is None:
format_string = "%(asctime)s %(name)s:%(lineno)d Rank:{0} [%(levelname)s] %(message)s".format(
rank)
global logger
logger = logging.getLogger(name)
logger.setLevel(logging.DEBUG)
handler = logging.FileHandler(filename)
handler.setLevel(level)
formatter = logging.Formatter(format_string, datefmt='%Y-%m-%d %H:%M:%S')
handler.setFormatter(formatter)
logger.addHandler(handler)
示例13: _enable_logging
# 需要导入模块: import logging [as 别名]
# 或者: from logging import LEVEL [as 别名]
def _enable_logging(logger, filename='py_cui_log.txt', logging_level=logging.DEBUG):
"""Function that creates basic logging configuration for selected logger
Parameters
----------
logger : PyCUILogger
Main logger object
filename : os.Pathlike
File path for output logfile
logging_level : logging.LEVEL, optional
Level of messages to display, by default logging.DEBUG
Raises
------
PermissionError
py_cui logs require permission to cwd to operate.
TypeError
Only the custom PyCUILogger can be used here.
"""
abs_path = os.path.abspath(filename)
if not os.access(os.path.dirname(abs_path), os.W_OK):
raise PermissionError('You do not have permission to create py_cui.log file.')
if not isinstance(logger, PyCUILogger):
raise TypeError('Only the PyCUILogger can be used for logging in the py_cui module.')
log_file = logging.FileHandler(filename)
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s | %(message)s')
log_file.setFormatter(formatter)
logger.addHandler(log_file)
logger.setLevel(logging_level)