Configuring Logging#
Jupyter Server (and Jupyter Server extension applications such as Jupyter Lab) are Traitlets applications.
By default Traitlets applications log to stderr. You can configure them to log to other locations e.g. log files.
Logging is configured via the logging_config “trait” which accepts a
logging.config.dictConfig() object. For more information look for
Application.logging_config in Config file and command line options.
Examples#
Jupyter Server#
A minimal example which logs Jupyter Server output to a file:
c.ServerApp.logging_config = {
"version": 1,
"handlers": {
"logfile": {
"class": "logging.FileHandler",
"level": "DEBUG",
"filename": "jupyter_server.log",
},
},
"loggers": {
"ServerApp": {
"level": "DEBUG",
"handlers": ["console", "logfile"],
},
},
}
Note
To keep the default behaviour of logging to stderr ensure the console
handler (provided by Traitlets) is included in the list of handlers.
Warning
Be aware that the ServerApp log may contain security tokens. If
redirecting to log files ensure they have appropriate permissions.
Configuring Log Scrubbing#
By default, Jupyter Server scrubs sensitive URL parameters from log output to prevent
security tokens and other sensitive information from being leaked in log files. Additional
parameters to be scrubbed can be configured using the extra_log_scrub_param_keys trait.
Default scrubbed parameter keys include: token, auth, key, code, state, and xsrf.
Example configuration to add additional parameters to scrub:
# jupyter_server_config.py
# Add additional parameter keys to scrub (these will be added to the defaults)
c.ServerApp.extra_log_scrub_param_keys = [
"password", "secret", "api_key", "jwt-token"
]
Jupyter Server Extension Applications (e.g. Jupyter Lab)#
An example which logs both Jupyter Server and Jupyter Lab output to a file:
Note
Because Jupyter Server and its extension applications are separate Traitlets applications their logging must be configured separately.
c.ServerApp.logging_config = {
"version": 1,
"handlers": {
"logfile": {
"class": "logging.FileHandler",
"level": "DEBUG",
"filename": "jupyter_server.log",
"formatter": "my_format",
},
},
"formatters": {
"my_format": {
"format": "%(asctime)s %(levelname)-8s %(name)-15s %(message)s",
"datefmt": "%Y-%m-%d %H:%M:%S",
},
},
"loggers": {
"ServerApp": {
"level": "DEBUG",
"handlers": ["console", "logfile"],
},
},
}
c.LabApp.logging_config = {
"version": 1,
"handlers": {
"logfile": {
"class": "logging.FileHandler",
"level": "DEBUG",
"filename": "jupyter_server.log",
"formatter": "my_format",
},
},
"formatters": {
"my_format": {
"format": "%(asctime)s %(levelname)-8s %(name)-15s %(message)s",
"datefmt": "%Y-%m-%d %H:%M:%S",
},
},
"loggers": {
"LabApp": {
"level": "DEBUG",
"handlers": ["console", "logfile"],
},
},
}
Note
The configured application name should match the logger name
e.g. c.LabApp.logging_config defines a logger called LabApp.
Tip
This diff modifies the example to log Jupyter Server and Jupyter Lab output to different files:
--- before
+++ after
c.LabApp.logging_config = {
'version': 1,
'handlers': {
'logfile': {
'class': 'logging.FileHandler',
'level': 'DEBUG',
- 'filename': 'jupyter_server.log',
+ 'filename': 'jupyter_lab.log',
'formatter': 'my_format',
},
},