本文整理汇总了Python中logbook.StreamHandler方法的典型用法代码示例。如果您正苦于以下问题:Python logbook.StreamHandler方法的具体用法?Python logbook.StreamHandler怎么用?Python logbook.StreamHandler使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类logbook
的用法示例。
在下文中一共展示了logbook.StreamHandler方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: global_init
# 需要导入模块: import logbook [as 别名]
# 或者: from logbook import StreamHandler [as 别名]
def global_init(log_level_text, filename):
level = LogService.__get_logbook_logging_level(log_level_text)
if not filename:
logbook.StreamHandler(sys.stdout, level=level).push_application()
else:
logbook.TimedRotatingFileHandler(
filename, level=level,
date_format="%Y-%m-%d").push_application()
msg = 'Logging initialized, level: {}, mode: {}'.format(
log_level_text,
"stdout mode" if not filename else 'file mode: ' + filename
)
LogService.get_startup_log().notice(msg)
示例2: configure_logger
# 需要导入模块: import logbook [as 别名]
# 或者: from logbook import StreamHandler [as 别名]
def configure_logger():
"""Configure a logger object"""
global _logger_configured
# Don't configure the logger multiple times
if _logger_configured:
return
# The StreamHandler will log everything to stdout
min_level = 'DEBUG' if 'BOTOGRAM_DEBUG' in os.environ else 'INFO'
handler = logbook.StreamHandler(sys.stdout, level=min_level)
handler.format_string = '{record.time.hour:0>2}:{record.time.minute:0>2}' \
'.{record.time.second:0>2} - ' \
'{record.level_name:^9} - {record.message}'
handler.push_application()
# Don't reconfigure the logger, thanks
_logger_configured = True
示例3: unsnooze_handler
# 需要导入模块: import logbook [as 别名]
# 或者: from logbook import StreamHandler [as 别名]
def unsnooze_handler(args):
if not (args.host or args.issue_name or args.all):
sys.exit('If you really want to unsnooze all issues for all hosts,\n'
'you need to specify --all.')
hostname = (None if not args.host else
args.host[0] if len(args.host) == 1 else
{'$in': args.host})
issue_name = (None if not args.issue_name else
args.issue_name[0] if len(args.issue_name) == 1
else {'$in': args.issue_name})
ids = unsnooze_issue(hostname, issue_name)
if not ids:
print('No matching issues.')
return
with logbook.StreamHandler(sys.stdout, bubble=True):
for doc in get_db().issues.find({'_id': {'$in': ids}}):
log.info('Unsnoozed {} {} at {}', doc['hostname'], doc['name'],
doc['unsnoozed_at'])
示例4: set_handler
# 需要导入模块: import logbook [as 别名]
# 或者: from logbook import StreamHandler [as 别名]
def set_handler(args):
old_value = get_client_parameter(args.hostname, args.parameter)
try:
old = set_client_parameter(args.hostname, args.parameter, args.value)
except Exception as e:
sys.exit('Failed to set parameter: {}'.format(e))
if not old_value:
with logbook.StreamHandler(sys.stdout, bubble=True):
log.info('Set parameter {} for host {} to {}',
args.parameter, args.hostname, args.value)
elif old:
with logbook.StreamHandler(sys.stdout, bubble=True):
log.info('Changed parameter {} for host {} from {} to {}',
args.parameter, args.hostname, old, args.value)
else:
print('No changes.')
示例5: post_fork
# 需要导入模块: import logbook [as 别名]
# 或者: from logbook import StreamHandler [as 别名]
def post_fork(server, worker):
server.log.info('Worker spawned (pid: %s)', worker.pid)
logging_rotating_file_handler = logging.handlers.RotatingFileHandler(
config.LOG_FILE_PATH.replace('.log', f'.{worker.pid}.flask.log'),
maxBytes=5 * 1024 * 1024,
backupCount=5,
)
root_logger = logging.getLogger()
root_logger.addHandler(logging_rotating_file_handler)
root_logger.setLevel(logging.CRITICAL)
logger_setup = logbook.NestedSetup(
[
logbook.StreamHandler(sys.stdout, level=logbook.INFO, bubble=True),
logbook.RotatingFileHandler(
config.LOG_FILE_PATH.replace('.log', f'.{worker.pid}.log'),
level=logbook.INFO,
max_size=5 * 1024 * 1024,
bubble=True,
),
]
)
logger_setup.push_application()
示例6: __init__
# 需要导入模块: import logbook [as 别名]
# 或者: from logbook import StreamHandler [as 别名]
def __init__(self, *args, **kwargs):
self.plug = (np.random.rand(100, 200, 3) * 255).astype(dtype=np.uint8)
self.params = {'rendering': 'disabled'}
self.render_modes = []
# self.log_level = WARNING
# StreamHandler(sys.stdout).push_application()
# self.log = Logger('BTgymRenderer', level=self.log_level)
示例7: snooze_handler
# 需要导入模块: import logbook [as 别名]
# 或者: from logbook import StreamHandler [as 别名]
def snooze_handler(args):
if not (args.host or args.issue_name or args.all):
sys.exit('If you really want to snooze all issues for all hosts,\n'
'you need to specify --all.')
if not (args.days or args.hours):
args.days = 1
if args.days:
then = now + datetime.timedelta(days=args.days)
else:
then = now + datetime.timedelta(hours=args.hours)
hostname = (None if not args.host else
args.host[0] if len(args.host) == 1 else
{'$in': args.host})
issue_name = (None if not args.issue_name else
args.issue_name[0] if len(args.issue_name) == 1
else {'$in': args.issue_name})
ids = snooze_issue(hostname, issue_name, then)
if not ids:
print('No matching issues.')
return
with logbook.StreamHandler(sys.stdout, bubble=True):
for doc in get_db().issues.find({'_id': {'$in': ids}}):
log.info('Snoozed {} {} until {}', doc['hostname'], doc['name'],
then)
示例8: suspend_handler
# 需要导入模块: import logbook [as 别名]
# 或者: from logbook import StreamHandler [as 别名]
def suspend_handler(args):
matches = suspend_host(args.host)
if not matches:
print('No matching, unsuspended hosts.')
return
with logbook.StreamHandler(sys.stdout, bubble=True):
for host in matches:
log.info('Suspended {}', host)
示例9: unsuspend_handler
# 需要导入模块: import logbook [as 别名]
# 或者: from logbook import StreamHandler [as 别名]
def unsuspend_handler(args):
matches = unsuspend_host(args.host)
if not matches:
print('No matching, suspended hosts.')
return
with logbook.StreamHandler(sys.stdout, bubble=True):
for host in matches:
log.info('Unsuspended {}', host)
示例10: open_handler
# 需要导入模块: import logbook [as 别名]
# 或者: from logbook import StreamHandler [as 别名]
def open_handler(args):
with logbook.StreamHandler(sys.stdout, bubble=True):
for host in args.host:
for issue in args.issue_name:
if open_issue(host, issue):
log.info('Manually opened {} issue for {}', issue, host)
else:
print('Open {} issue for {} already exists.'.format(
issue, host))
示例11: unset_handler
# 需要导入模块: import logbook [as 别名]
# 或者: from logbook import StreamHandler [as 别名]
def unset_handler(args):
try:
old = set_client_parameter(args.hostname, args.parameter, None)
except Exception as e:
sys.exit('Failed to unset parameter: {}'.format(e))
if old:
with logbook.StreamHandler(sys.stdout, bubble=True):
log.info('Unset parameter {} for host {} (was {})', args.parameter,
args.hostname, old)
else:
print('No changes.')
示例12: global_init
# 需要导入模块: import logbook [as 别名]
# 或者: from logbook import StreamHandler [as 别名]
def global_init(logfile):
if logfile:
logbook.TimedRotatingFileHandler(
logfile, level=logbook.INFO, date_format='%Y-%m-%d').push_application()
else:
logbook.StreamHandler(sys.stdout, level=logbook.TRACE).push_application()
示例13: get_logger
# 需要导入模块: import logbook [as 别名]
# 或者: from logbook import StreamHandler [as 别名]
def get_logger(name, debug=True):
logbook.set_datetime_format('local')
handler = StreamHandler(sys.stdout) if debug else NullHandler()
handler.push_application()
return Logger(os.path.basename(name))
示例14: main
# 需要导入模块: import logbook [as 别名]
# 或者: from logbook import StreamHandler [as 别名]
def main():
logbook.StreamHandler(sys.stdout).push_application()
app.run(host, port)
示例15: _get_event_handler
# 需要导入模块: import logbook [as 别名]
# 或者: from logbook import StreamHandler [as 别名]
def _get_event_handler(self):
"""
Retrieves the correct event handler. Returns a Stream Handler
if the event should write to STDOUT, otherwise it will return
a ready RotatingFileHandler.
Both subclasses inherit from the StreamHandler base class.
:return: Event handler
:rtype: StreamHandler
"""
if self.filename.upper() == 'STDOUT':
return StreamHandler(sys.stdout)
else:
fs.create_dir(os.path.dirname(self.filename))
previous_log_file_exists = os.path.exists(self.filename)
event_handler = RotatingFileHandler(
filename=self.filename,
max_size=Configuration['max_eventlog_file_fize'],
backup_count=Configuration['max_eventlog_file_backups']
)
if previous_log_file_exists:
event_handler.perform_rollover() # force starting a new eventlog file on application startup
return event_handler