mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
Rework logging configuration
This commit is contained in:
parent
c931f8a532
commit
fcf9e58ce4
1 changed files with 74 additions and 121 deletions
|
@ -93,129 +93,82 @@ def init_logging(interface="cli",
|
||||||
if not os.path.isdir(logdir):
|
if not os.path.isdir(logdir):
|
||||||
os.makedirs(logdir, 0o750)
|
os.makedirs(logdir, 0o750)
|
||||||
|
|
||||||
# ####################################################################### #
|
logging_configuration = {
|
||||||
|
'version': 1,
|
||||||
|
'disable_existing_loggers': True,
|
||||||
|
'formatters': {
|
||||||
|
'console': {
|
||||||
|
'format': '%(relativeCreated)-5d %(levelname)-8s %(name)s %(funcName)s - %(fmessage)s'
|
||||||
|
},
|
||||||
|
'tty-debug': {
|
||||||
|
'format': '%(relativeCreated)-4d %(fmessage)s'
|
||||||
|
},
|
||||||
|
'precise': {
|
||||||
|
'format': '%(asctime)-15s %(levelname)-8s %(name)s %(funcName)s - %(fmessage)s'
|
||||||
|
},
|
||||||
|
},
|
||||||
|
'filters': {
|
||||||
|
'action': {
|
||||||
|
'()': 'moulinette.utils.log.ActionFilter',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
'handlers': {
|
||||||
|
'cli': {
|
||||||
|
'level': 'DEBUG' if debug else 'INFO',
|
||||||
|
'class': 'moulinette.interfaces.cli.TTYHandler',
|
||||||
|
'formatter': 'tty-debug' if debug else '',
|
||||||
|
},
|
||||||
|
'api': {
|
||||||
|
'level': 'DEBUG' if debug else 'INFO',
|
||||||
|
'class': 'moulinette.interfaces.api.APIQueueHandler',
|
||||||
|
},
|
||||||
|
'file': {
|
||||||
|
'class': 'logging.FileHandler',
|
||||||
|
'formatter': 'precise',
|
||||||
|
'filename': logfile,
|
||||||
|
'filters': ['action'],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
'loggers': {
|
||||||
|
'yunohost': {
|
||||||
|
'level': 'DEBUG',
|
||||||
|
'handlers': ['file', interface] if not quiet else ['file'],
|
||||||
|
'propagate': False,
|
||||||
|
},
|
||||||
|
'moulinette': {
|
||||||
|
'level': 'DEBUG',
|
||||||
|
'handlers': ['file', interface] if not quiet else ['file'],
|
||||||
|
'propagate': False,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
'root': {
|
||||||
|
'level': 'DEBUG',
|
||||||
|
'handlers': ['file', interface] if debug else ['file'],
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
# Logging configuration for CLI (or any other interface than api...) #
|
# Logging configuration for CLI (or any other interface than api...) #
|
||||||
# ####################################################################### #
|
|
||||||
if interface != "api":
|
if interface != "api":
|
||||||
configure_logging({
|
|
||||||
'version': 1,
|
logging_configuration["main_logger"] = "yunohost"
|
||||||
'main_logger': "yunohost",
|
|
||||||
'disable_existing_loggers': True,
|
configure_logging(logging_configuration)
|
||||||
'formatters': {
|
|
||||||
'tty-debug': {
|
|
||||||
'format': '%(relativeCreated)-4d %(fmessage)s'
|
|
||||||
},
|
|
||||||
'precise': {
|
|
||||||
'format': '%(asctime)-15s %(levelname)-8s %(name)s %(funcName)s - %(fmessage)s'
|
|
||||||
},
|
|
||||||
},
|
|
||||||
'filters': {
|
|
||||||
'action': {
|
|
||||||
'()': 'moulinette.utils.log.ActionFilter',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
'handlers': {
|
|
||||||
'tty': {
|
|
||||||
'level': 'DEBUG' if debug else 'INFO',
|
|
||||||
'class': 'moulinette.interfaces.cli.TTYHandler',
|
|
||||||
'formatter': 'tty-debug' if debug else '',
|
|
||||||
},
|
|
||||||
'file': {
|
|
||||||
'class': 'logging.FileHandler',
|
|
||||||
'formatter': 'precise',
|
|
||||||
'filename': logfile,
|
|
||||||
'filters': ['action'],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
'loggers': {
|
|
||||||
'yunohost': {
|
|
||||||
'level': 'DEBUG',
|
|
||||||
'handlers': ['file', 'tty'] if not quiet else ['file'],
|
|
||||||
'propagate': False,
|
|
||||||
},
|
|
||||||
'moulinette': {
|
|
||||||
'level': 'DEBUG',
|
|
||||||
'handlers': [],
|
|
||||||
'propagate': True,
|
|
||||||
},
|
|
||||||
'moulinette.interface': {
|
|
||||||
'level': 'DEBUG',
|
|
||||||
'handlers': ['file', 'tty'] if not quiet else ['file'],
|
|
||||||
'propagate': False,
|
|
||||||
},
|
|
||||||
'moulinette.core': {
|
|
||||||
'level': 'DEBUG' if debug else 'ERROR',
|
|
||||||
'handlers': ['file', 'tty'] if not quiet else ['file'],
|
|
||||||
'propagate': False,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
'root': {
|
|
||||||
'level': 'DEBUG',
|
|
||||||
'handlers': ['file', 'tty'] if debug else ['file'],
|
|
||||||
},
|
|
||||||
})
|
|
||||||
# ####################################################################### #
|
|
||||||
# Logging configuration for API #
|
# Logging configuration for API #
|
||||||
# ####################################################################### #
|
|
||||||
else:
|
else:
|
||||||
configure_logging({
|
# We use a WatchedFileHandler instead of regular FileHandler to possibly support log rotation etc
|
||||||
'version': 1,
|
logging_configuration["handlers"]["file"]["class"] = 'logging.handlers.WatchedFileHandler'
|
||||||
'disable_existing_loggers': True,
|
|
||||||
'formatters': {
|
# This is for when launching yunohost-api in debug mode, we want to display stuff in the console
|
||||||
'console': {
|
if debug:
|
||||||
'format': '%(relativeCreated)-5d %(levelname)-8s %(name)s %(funcName)s - %(fmessage)s'
|
logging_configuration["handlers"]["console"] = {
|
||||||
},
|
'class': 'logging.StreamHandler',
|
||||||
'precise': {
|
'formatter': 'console',
|
||||||
'format': '%(asctime)-15s %(levelname)-8s %(name)s %(funcName)s - %(fmessage)s'
|
'stream': 'ext://sys.stdout',
|
||||||
},
|
'filters': ['action'],
|
||||||
},
|
},
|
||||||
'filters': {
|
logging_configuration["loggers"]["yunohost"]["handlers"].append("console")
|
||||||
'action': {
|
logging_configuration["loggers"]["moulinette"]["handlers"].append("console")
|
||||||
'()': 'moulinette.utils.log.ActionFilter',
|
logging_configuration["root"]["handlers"].append("console")
|
||||||
},
|
|
||||||
},
|
configure_logging(logging_configuration)
|
||||||
'handlers': {
|
|
||||||
'api': {
|
|
||||||
'level': 'DEBUG' if debug else 'INFO',
|
|
||||||
'class': 'moulinette.interfaces.api.APIQueueHandler',
|
|
||||||
},
|
|
||||||
'file': {
|
|
||||||
'class': 'logging.handlers.WatchedFileHandler',
|
|
||||||
'formatter': 'precise',
|
|
||||||
'filename': logfile,
|
|
||||||
'filters': ['action'],
|
|
||||||
},
|
|
||||||
'console': {
|
|
||||||
'class': 'logging.StreamHandler',
|
|
||||||
'formatter': 'console',
|
|
||||||
'stream': 'ext://sys.stdout',
|
|
||||||
'filters': ['action'],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
'loggers': {
|
|
||||||
'yunohost': {
|
|
||||||
'level': 'DEBUG',
|
|
||||||
'handlers': ['file', 'api'] + (['console'] if debug else []),
|
|
||||||
'propagate': False,
|
|
||||||
},
|
|
||||||
'moulinette': {
|
|
||||||
'level': 'DEBUG',
|
|
||||||
'handlers': [],
|
|
||||||
'propagate': True,
|
|
||||||
},
|
|
||||||
'moulinette.core': {
|
|
||||||
'level': 'DEBUG' if debug else 'ERROR',
|
|
||||||
'handlers': ['file', 'tty'] if not quiet else ['file'],
|
|
||||||
'propagate': False,
|
|
||||||
},
|
|
||||||
'moulinette.interface.api': {
|
|
||||||
'level': 'DEBUG',
|
|
||||||
'handlers': [],
|
|
||||||
'propagate': True,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
'root': {
|
|
||||||
'level': 'DEBUG',
|
|
||||||
'handlers': ['file'] + (['console'] if debug else []),
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue