本文整理匯總了Python中logbook.INFO屬性的典型用法代碼示例。如果您正苦於以下問題:Python logbook.INFO屬性的具體用法?Python logbook.INFO怎麽用?Python logbook.INFO使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類logbook
的用法示例。
在下文中一共展示了logbook.INFO屬性的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: post_fork
# 需要導入模塊: import logbook [as 別名]
# 或者: from logbook import INFO [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()
示例2: __get_logbook_logging_level
# 需要導入模塊: import logbook [as 別名]
# 或者: from logbook import INFO [as 別名]
def __get_logbook_logging_level(level_str):
# logbook levels:
# CRITICAL = 15
# ERROR = 14
# WARNING = 13
# NOTICE = 12
# INFO = 11
# DEBUG = 10
# TRACE = 9
# NOTSET = 0
level_str = level_str.upper().strip()
if level_str == 'CRITICAL':
return logbook.CRITICAL
elif level_str == 'ERROR':
return logbook.ERROR
elif level_str == 'WARNING':
return logbook.WARNING
elif level_str == 'NOTICE':
return logbook.NOTICE
elif level_str == 'INFO':
return logbook.INFO
elif level_str == 'DEBUG':
return logbook.DEBUG
elif level_str == 'TRACE':
return logbook.TRACE
elif level_str == 'NOTSET':
return logbook.NOTSET
else:
raise ValueError("Unknown logbook log level: {}".format(level_str))
示例3: _get_logging_level
# 需要導入模塊: import logbook [as 別名]
# 或者: from logbook import INFO [as 別名]
def _get_logging_level(verbosity: int) -> LogbookLevel:
import logbook
return LogbookLevel({
1: logbook.CRITICAL,
2: logbook.ERROR,
3: logbook.WARNING,
4: logbook.NOTICE,
5: logbook.INFO,
6: logbook.DEBUG,
7: logbook.TRACE,
}[verbosity])
示例4: parse_log_level
# 需要導入模塊: import logbook [as 別名]
# 或者: from logbook import INFO [as 別名]
def parse_log_level(value):
# type: (str) -> logbook
value = value.lower()
if value == "info":
return logbook.INFO
elif value == "warning":
return logbook.WARNING
elif value == "error":
return logbook.ERROR
elif value == "debug":
return logbook.DEBUG
return logbook.WARNING
示例5: global_init
# 需要導入模塊: import logbook [as 別名]
# 或者: from logbook import INFO [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()
示例6: __init__
# 需要導入模塊: import logbook [as 別名]
# 或者: from logbook import INFO [as 別名]
def __init__(self,
log_level=LogLevel.INFO,
format_str='[{record.time:%Y-%m-%d %H:%M:%S}] - {record.channel} - {record.level_name} '
'- {record.message}'):
self.logger = Logger('WindAdapter')
set_datetime_format('local')
StreamHandler(sys.stdout, format_string=format_str).push_application()
FileHandler('WindAdapter.log', bubble=True, format_string=format_str).push_application()
self.set_level(log_level)
示例7: set_level
# 需要導入模塊: import logbook [as 別名]
# 或者: from logbook import INFO [as 別名]
def set_level(self, log_level):
if log_level.lower() == LogLevel.INFO:
self.logger.level = logbook.INFO
elif log_level.lower() == LogLevel.WARNING:
self.logger.level = logbook.WARNING
elif log_level.lower() == LogLevel.CRITICAL:
self.logger.level = logbook.CRITICAL
elif log_level.lower() == LogLevel.NOTSET:
self.logger.level = logbook.NOTSET
示例8: _get_log_handlers
# 需要導入模塊: import logbook [as 別名]
# 或者: from logbook import INFO [as 別名]
def _get_log_handlers(verbose):
return [logbook.StreamHandler(sys.stdout, level=logbook.DEBUG if verbose else logbook.INFO, bubble=True)]
示例9: setup_papertrail
# 需要導入模塊: import logbook [as 別名]
# 或者: from logbook import INFO [as 別名]
def setup_papertrail(project_name, channel, PAPERTRAIL_HOST, PAPERTRAIL_PORT):
"""
Setup papertrail account using taskcluster secrets
"""
# Setup papertrail
papertrail = logbook.SyslogHandler(
application_name=f"code-coverage/{channel}/{project_name}",
address=(PAPERTRAIL_HOST, int(PAPERTRAIL_PORT)),
level=logbook.INFO,
format_string="{record.time} {record.channel}: {record.message}",
bubble=True,
)
papertrail.push_application()
示例10: setup_papertrail
# 需要導入模塊: import logbook [as 別名]
# 或者: from logbook import INFO [as 別名]
def setup_papertrail(project_name, channel, PAPERTRAIL_HOST, PAPERTRAIL_PORT):
"""
Setup papertrail account using taskcluster secrets
"""
# Setup papertrail
papertrail = logbook.SyslogHandler(
application_name=f"code-review/{channel}/{project_name}",
address=(PAPERTRAIL_HOST, int(PAPERTRAIL_PORT)),
level=logbook.INFO,
format_string="{record.time} {record.channel}: {record.message}",
bubble=True,
)
papertrail.push_application()
示例11: configure_logging
# 需要導入模塊: import logbook [as 別名]
# 或者: from logbook import INFO [as 別名]
def configure_logging(log_level=None, log_file=None, simplified_console_logs=False):
"""
This should be called once as early as possible in app startup to configure logging handlers and formatting.
:param log_level: The level at which to record log messages (DEBUG|INFO|NOTICE|WARNING|ERROR|CRITICAL)
:type log_level: str
:param log_file: The file to write logs to, or None to disable logging to a file
:type log_file: str | None
:param simplified_console_logs: Whether or not to use the simplified logging format and coloring
:type simplified_console_logs: bool
"""
# Set datetimes in log messages to be local timezone instead of UTC
logbook.set_datetime_format('local')
# Redirect standard lib logging to capture third-party logs in our log files (e.g., tornado, requests)
logging.root.setLevel(logging.WARNING) # don't include DEBUG/INFO/NOTICE-level logs from third parties
logbook.compat.redirect_logging(set_root_logger_level=False)
# Add a NullHandler to suppress all log messages lower than our desired log_level. (Otherwise they go to stderr.)
NullHandler().push_application()
log_level = log_level or Configuration['log_level']
format_string, log_colors = _LOG_FORMAT_STRING, _LOG_COLORS
if simplified_console_logs:
format_string, log_colors = _SIMPLIFIED_LOG_FORMAT_STRING, _SIMPLIFIED_LOG_COLORS
# handler for stdout
log_handler = _ColorizingStreamHandler(
stream=sys.stdout,
level=log_level,
format_string=format_string,
log_colors=log_colors,
bubble=True,
)
log_handler.push_application()
# handler for log file
if log_file:
fs.create_dir(os.path.dirname(log_file))
previous_log_file_exists = os.path.exists(log_file)
event_handler = _ColorizingRotatingFileHandler(
filename=log_file,
level=log_level,
format_string=_LOG_FORMAT_STRING,
log_colors=_LOG_COLORS,
bubble=True,
max_size=Configuration['max_log_file_size'],
backup_count=Configuration['max_log_file_backups'],
)
event_handler.push_application()
if previous_log_file_exists:
# Force application to create a new log file on startup.
event_handler.perform_rollover(increment_logfile_counter=False)
else:
event_handler.log_application_summary()
示例12: init_logger
# 需要導入模塊: import logbook [as 別名]
# 或者: from logbook import INFO [as 別名]
def init_logger(
project_name,
channel=None,
level=logbook.INFO,
PAPERTRAIL_HOST=None,
PAPERTRAIL_PORT=None,
sentry_dsn=None,
):
if not channel:
channel = os.environ.get("APP_CHANNEL")
# Output logs on stderr, with color support on consoles
fmt = "{record.time} [{record.level_name:<8}] {record.channel}: {record.message}"
handler = logbook.more.ColorizedStderrHandler(level=level, format_string=fmt)
handler.push_application()
# Log to papertrail
if channel and PAPERTRAIL_HOST and PAPERTRAIL_PORT:
setup_papertrail(project_name, channel, PAPERTRAIL_HOST, PAPERTRAIL_PORT)
# Log to senty
if channel and sentry_dsn:
setup_sentry(project_name, channel, sentry_dsn)
def logbook_factory(*args, **kwargs):
# Logger given to structlog
logbook.compat.redirect_logging()
return logbook.Logger(level=level, *args, **kwargs)
# Setup structlog over logbook, with args list at the end
processors = [
structlog.stdlib.PositionalArgumentsFormatter(),
structlog.processors.StackInfoRenderer(),
structlog.processors.format_exc_info,
UnstructuredRenderer(),
]
structlog.configure(
context_class=structlog.threadlocal.wrap_dict(dict),
processors=processors,
logger_factory=logbook_factory,
wrapper_class=structlog.stdlib.BoundLogger,
cache_logger_on_first_use=True,
)
示例13: init_logger
# 需要導入模塊: import logbook [as 別名]
# 或者: from logbook import INFO [as 別名]
def init_logger(
project_name,
channel=None,
level=logbook.INFO,
PAPERTRAIL_HOST=None,
PAPERTRAIL_PORT=None,
SENTRY_DSN=None,
):
if not channel:
channel = os.environ.get("APP_CHANNEL")
# Output logs on stderr, with color support on consoles
fmt = "{record.time} [{record.level_name:<8}] {record.channel}: {record.message}"
handler = logbook.more.ColorizedStderrHandler(level=level, format_string=fmt)
handler.push_application()
# Log to papertrail
if channel and PAPERTRAIL_HOST and PAPERTRAIL_PORT:
setup_papertrail(project_name, channel, PAPERTRAIL_HOST, PAPERTRAIL_PORT)
# Log to senty
if channel and SENTRY_DSN:
setup_sentry(project_name, channel, SENTRY_DSN)
def logbook_factory(*args, **kwargs):
# Logger given to structlog
logbook.compat.redirect_logging()
return logbook.Logger(level=level, *args, **kwargs)
# Setup structlog over logbook, with args list at the end
processors = [
structlog.stdlib.PositionalArgumentsFormatter(),
structlog.processors.StackInfoRenderer(),
structlog.processors.format_exc_info,
UnstructuredRenderer(),
]
structlog.configure(
context_class=structlog.threadlocal.wrap_dict(dict),
processors=processors,
logger_factory=logbook_factory,
wrapper_class=structlog.stdlib.BoundLogger,
cache_logger_on_first_use=True,
)