本文整理汇总了Python中logging.INFO属性的典型用法代码示例。如果您正苦于以下问题:Python logging.INFO属性的具体用法?Python logging.INFO怎么用?Python logging.INFO使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类logging
的用法示例。
在下文中一共展示了logging.INFO属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_logger
# 需要导入模块: import logging [as 别名]
# 或者: from logging import INFO [as 别名]
def get_logger(cls,logger_name,create_file=False):
# create logger for prd_ci
log = logging.getLogger(logger_name)
log.setLevel(level=logging.INFO)
# create formatter and add it to the handlers
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
if create_file:
# create file handler for logger.
fh = logging.FileHandler('SPOT.log')
fh.setLevel(level=logging.DEBUG)
fh.setFormatter(formatter)
# reate console handler for logger.
ch = logging.StreamHandler()
ch.setLevel(level=logging.DEBUG)
ch.setFormatter(formatter)
# add handlers to logger.
if create_file:
log.addHandler(fh)
log.addHandler(ch)
return log
示例2: setup_logging
# 需要导入模块: import logging [as 别名]
# 或者: from logging import INFO [as 别名]
def setup_logging(log_dir):
log_file_format = "[%(levelname)s] - %(asctime)s - %(name)s - : %(message)s in %(pathname)s:%(lineno)d"
log_console_format = "[%(levelname)s]: %(message)s"
# Main logger
main_logger = logging.getLogger()
main_logger.setLevel(logging.INFO)
console_handler = logging.StreamHandler()
console_handler.setLevel(logging.INFO)
console_handler.setFormatter(Formatter(log_console_format))
exp_file_handler = RotatingFileHandler('{}exp_debug.log'.format(log_dir), maxBytes=10**6, backupCount=5)
exp_file_handler.setLevel(logging.DEBUG)
exp_file_handler.setFormatter(Formatter(log_file_format))
exp_errors_file_handler = RotatingFileHandler('{}exp_error.log'.format(log_dir), maxBytes=10**6, backupCount=5)
exp_errors_file_handler.setLevel(logging.WARNING)
exp_errors_file_handler.setFormatter(Formatter(log_file_format))
main_logger.addHandler(console_handler)
main_logger.addHandler(exp_file_handler)
main_logger.addHandler(exp_errors_file_handler)
示例3: init_logging
# 需要导入模块: import logging [as 别名]
# 或者: from logging import INFO [as 别名]
def init_logging(log_file=None, append=False, console_loglevel=logging.INFO):
"""Set up logging to file and console."""
if log_file is not None:
if append:
filemode_val = 'a'
else:
filemode_val = 'w'
logging.basicConfig(level=logging.DEBUG,
format="%(asctime)s %(levelname)s %(threadName)s %(name)s %(message)s",
# datefmt='%m-%d %H:%M',
filename=log_file,
filemode=filemode_val)
# define a Handler which writes INFO messages or higher to the sys.stderr
console = logging.StreamHandler()
console.setLevel(console_loglevel)
# set a format which is simpler for console use
formatter = logging.Formatter("%(message)s")
console.setFormatter(formatter)
# add the handler to the root logger
logging.getLogger('').addHandler(console)
global LOG
LOG = logging.getLogger(__name__)
示例4: __init__
# 需要导入模块: import logging [as 别名]
# 或者: from logging import INFO [as 别名]
def __init__(self, model_nm, logfile=None, props=None,
loglevel=logging.INFO):
self.model_nm = model_nm
self.graph = nx.Graph()
if props is None:
self.props = {}
else:
self.props = props
logfile = self.get("log_fname")
self.logger = Logger(self, model_name=model_nm,logfile=logfile)
self.graph.add_edge(self, self.logger)
self["OS"] = platform.system()
self["model"] = model_nm
# process command line args and set them as properties:
prop_nm = None
for arg in sys.argv:
# the first arg (-prop) names the property
if arg.startswith(SWITCH):
prop_nm = arg.lstrip(SWITCH)
# the second arg is the property value
elif prop_nm is not None:
self[prop_nm] = arg
prop_nm = None
示例5: get_logger
# 需要导入模块: import logging [as 别名]
# 或者: from logging import INFO [as 别名]
def get_logger(cls, logger_name, create_file=False):
# create logger for prd_ci
log = logging.getLogger(logger_name)
log.setLevel(level=logging.INFO)
# create formatter and add it to the handlers
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
if create_file:
# create file handler for logger.
fh = logging.FileHandler('oa.log')
fh.setLevel(level=logging.DEBUG)
fh.setFormatter(formatter)
# reate console handler for logger.
ch = logging.StreamHandler()
ch.setLevel(level=logging.DEBUG)
ch.setFormatter(formatter)
# add handlers to logger.
if create_file:
log.addHandler(fh)
log.addHandler(ch)
return log
示例6: parse_args
# 需要导入模块: import logging [as 别名]
# 或者: from logging import INFO [as 别名]
def parse_args():
parser = argparse.ArgumentParser(description = "Bass")
parser.add_argument("-v", "--verbose", action = "count", default = 0, help = "Increase verbosity")
parser.add_argument("samples", metavar = "sample", nargs = "+", help = "Sample path")
args = parser.parse_args()
try:
loglevel = {
0: logging.ERROR,
1: logging.WARN,
2: logging.INFO
}[args.verbose]
except KeyError:
loglevel = logging.DEBUG
logging.basicConfig(level = loglevel)
logging.getLogger().setLevel(loglevel)
return args
示例7: parse_args
# 需要导入模块: import logging [as 别名]
# 或者: from logging import INFO [as 别名]
def parse_args():
parser = argparse.ArgumentParser(description = "Add samples to BASS whitelist")
parser.add_argument("-v", "--verbose", action = "count", default = 0, help = "Increase verbosity")
parser.add_argument("--url", type = str, default = "http://localhost:5000", help = "URL of BASS server")
parser.add_argument("sample", help = "Whitelist sample")
args = parser.parse_args()
try:
loglevel = {
0: logging.ERROR,
1: logging.WARN,
2: logging.INFO}[args.verbose]
except KeyError:
loglevel = logging.DEBUG
logging.basicConfig(level = loglevel)
logging.getLogger().setLevel(loglevel)
return args
示例8: parse_args
# 需要导入模块: import logging [as 别名]
# 或者: from logging import INFO [as 别名]
def parse_args():
parser = argparse.ArgumentParser(description = "Find common ngrams in binary files")
parser.add_argument("-v", "--verbose", action = "count", default = 0, help = "Increase verbosity")
parser.add_argument("--output", type = str, default = None, help = "Output to file instead of stdout")
parser.add_argument("--url", type = str, default = "http://localhost:5000", help = "URL of BASS server")
parser.add_argument("samples", metavar = "sample", nargs = "+", help = "Cluster samples")
args = parser.parse_args()
try:
loglevel = {
0: logging.ERROR,
1: logging.WARN,
2: logging.INFO}[args.verbose]
except KeyError:
loglevel = logging.DEBUG
logging.basicConfig(level = loglevel)
logging.getLogger().setLevel(loglevel)
return args
示例9: __init__
# 需要导入模块: import logging [as 别名]
# 或者: from logging import INFO [as 别名]
def __init__(self, appid=None, logger_root='cherrypy'):
self.logger_root = logger_root
self.appid = appid
if appid is None:
self.error_log = logging.getLogger('%s.error' % logger_root)
self.access_log = logging.getLogger('%s.access' % logger_root)
else:
self.error_log = logging.getLogger(
'%s.error.%s' % (logger_root, appid))
self.access_log = logging.getLogger(
'%s.access.%s' % (logger_root, appid))
self.error_log.setLevel(logging.INFO)
self.access_log.setLevel(logging.INFO)
# Silence the no-handlers "warning" (stderr write!) in stdlib logging
self.error_log.addHandler(NullHandler())
self.access_log.addHandler(NullHandler())
cherrypy.engine.subscribe('graceful', self.reopen_files)
示例10: error
# 需要导入模块: import logging [as 别名]
# 或者: from logging import INFO [as 别名]
def error(self, msg='', context='', severity=logging.INFO,
traceback=False):
"""Write the given ``msg`` to the error log.
This is not just for errors! Applications may call this at any time
to log application-specific information.
If ``traceback`` is True, the traceback of the current exception
(if any) will be appended to ``msg``.
"""
exc_info = None
if traceback:
exc_info = _cperror._exc_info()
self.error_log.log(
severity,
' '.join((self.time(), context, msg)),
exc_info=exc_info,
)
示例11: main
# 需要导入模块: import logging [as 别名]
# 或者: from logging import INFO [as 别名]
def main(argv):
logging.basicConfig(level=logging.INFO)
log_history = LogHistory(argv.config, argv.flow_dir, argv.port_dir, int(argv.num_steps), debug=True)
channel = "sdx_stats"
address = "192.168.99.100"
port = 6379
db = 0
publisher = Publisher(channel, address, port)
log_replay = LogReplay(log_history, publisher, int(argv.timestep), debug=True)
# start replay
replay_thread = Thread(target=log_replay.start)
replay_thread.daemon = True
replay_thread.start()
while replay_thread.is_alive():
try:
replay_thread.join(1)
except KeyboardInterrupt:
log_replay.stop()
示例12: set_level
# 需要导入模块: import logging [as 别名]
# 或者: from logging import INFO [as 别名]
def set_level(self, level):
"""
Set the minimum level of messages to be logged.
Level of Log Messages
CRITICAL 50
ERROR 40
WARNING 30
INFO 20
DEBUG 10
NOTSET 0
@param level: minimum level of messages to be logged
@type level: int or long
@return: None
@rtype: None
"""
assert level in self._levelNames
list_of_handlers = self._logger.handlers
for handler in list_of_handlers:
handler.setLevel(level)
示例13: add_log_stream
# 需要导入模块: import logging [as 别名]
# 或者: from logging import INFO [as 别名]
def add_log_stream(self, stream=sys.stderr, level=logging.INFO):
"""
Add a stream where messages are outputted to.
@param stream: stderr/stdout or a file stream
@type stream: file | FileIO | StringIO
@param level: minimum level of messages to be logged
@type level: int | long
@return: None
@rtype: None
"""
assert self.is_stream(stream)
# assert isinstance(stream, (file, io.FileIO))
assert level in self._levelNames
err_handler = logging.StreamHandler(stream)
err_handler.setFormatter(self.message_formatter)
err_handler.setLevel(level)
self._logger.addHandler(err_handler)
示例14: set_log_level
# 需要导入模块: import logging [as 别名]
# 或者: from logging import INFO [as 别名]
def set_log_level(self, verbose, debug):
"""
Simplified way to set log level.
@attention verbose: Ignored if 'debug' true
@param verbose: Display info messages and higher
@type verbose: bool
@param debug: Display debug messages and higher
@type debug: bool
@return: Nothing
@rtype: None
"""
if debug:
self._logger.set_level(self._logger.DEBUG)
elif verbose:
self._logger.set_level(self._logger.INFO)
else:
self._logger.set_level(self._logger.WARNING)
示例15: set_level
# 需要导入模块: import logging [as 别名]
# 或者: from logging import INFO [as 别名]
def set_level(self, level):
"""
Set the minimum level of messages to be logged.
Level of Log Messages
CRITICAL 50
ERROR 40
WARNING 30
INFO 20
DEBUG 10
NOTSET 0
@param level: minimum level of messages to be logged
@type level: int or long
@return: None
@rtype: None
"""
assert level in self._levelNames
list_of_handlers = self._logger.handlers
for handler in list_of_handlers:
handler.setLevel(level)