mirror of
https://github.com/jupyterhub/jupyterhub.git
synced 2025-10-13 13:03:01 +00:00
DEV: Allow a list of log handlers.
This commit is contained in:
@@ -369,37 +369,32 @@ class JupyterHub(Application):
|
|||||||
extra_log_file = Unicode(
|
extra_log_file = Unicode(
|
||||||
"",
|
"",
|
||||||
config=True,
|
config=True,
|
||||||
help="""Set a FileHandler on this file.
|
help="Set a logging.FileHandler on this file."
|
||||||
|
|
||||||
Ignored if extra_log_handler is explicitly set in config file.
|
|
||||||
"""
|
|
||||||
)
|
)
|
||||||
extra_log_handler = Instance(
|
extra_log_handlers = List(
|
||||||
klass=logging.Handler,
|
Instance(logging.Handler),
|
||||||
allow_none=True,
|
|
||||||
config=True,
|
config=True,
|
||||||
help="Extra handler to set on JupyterHub logger.",
|
help="Extra log handlers to set on JupyterHub logger",
|
||||||
)
|
)
|
||||||
|
|
||||||
def _extra_log_handler_default(self):
|
|
||||||
if self.extra_log_file:
|
|
||||||
return logging.FileHandler(self.extra_log_file)
|
|
||||||
return None
|
|
||||||
|
|
||||||
def init_logging(self):
|
def init_logging(self):
|
||||||
# This prevents double log messages because tornado use a root logger that
|
# This prevents double log messages because tornado use a root logger that
|
||||||
# self.log is a child of. The logging module dipatches log messages to a log
|
# self.log is a child of. The logging module dipatches log messages to a log
|
||||||
# and all of its ancenstors until propagate is set to False.
|
# and all of its ancenstors until propagate is set to False.
|
||||||
self.log.propagate = False
|
self.log.propagate = False
|
||||||
|
|
||||||
if self.extra_log_handler:
|
if self.extra_log_file:
|
||||||
self.extra_log_handler.setFormatter(
|
self.extra_log_handlers.append(
|
||||||
self._log_formatter_cls(
|
logging.FileHandler(self.extra_log_file)
|
||||||
fmt=self.log_format,
|
|
||||||
datefmt=self.log_datefmt,
|
|
||||||
),
|
|
||||||
)
|
)
|
||||||
self.log.addHandler(self.extra_log_handler)
|
|
||||||
|
_formatter = self._log_formatter_cls(
|
||||||
|
fmt=self.log_format,
|
||||||
|
datefmt=self.log_datefmt,
|
||||||
|
)
|
||||||
|
for handler in self.extra_log_handlers:
|
||||||
|
handler.setFormatter(_formatter)
|
||||||
|
self.log.addHandler(handler)
|
||||||
|
|
||||||
# hook up tornado 3's loggers to our app handlers
|
# hook up tornado 3's loggers to our app handlers
|
||||||
for log in (app_log, access_log, gen_log):
|
for log in (app_log, access_log, gen_log):
|
||||||
|
Reference in New Issue
Block a user