Skip to content

Commit

Permalink
Merge branch 'main' into moar-coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
blink1073 authored Nov 16, 2022
2 parents 9c57c30 + 830c87f commit 95b642a
Show file tree
Hide file tree
Showing 6 changed files with 152 additions and 12 deletions.
15 changes: 5 additions & 10 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ repos:
files: \.py$

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v0.982
rev: v0.990
hooks:
- id: mypy
additional_dependencies: [types-requests]
Expand All @@ -47,7 +47,7 @@ repos:
- id: mdformat

- repo: https://github.com/asottile/pyupgrade
rev: v3.2.0
rev: v3.2.2
hooks:
- id: pyupgrade
args: [--py38-plus]
Expand Down Expand Up @@ -75,12 +75,7 @@ repos:
- id: eslint
stages: [manual]

- repo: https://github.com/sirosen/check-jsonschema
rev: 0.18.4
- repo: https://github.com/python-jsonschema/check-jsonschema
rev: 0.19.1
hooks:
- id: check-jsonschema
name: "Check GitHub Workflows"
files: ^\.github/workflows/
types: [yaml]
args: ["--schemafile", "https://json.schemastore.org/github-workflow"]
stages: [manual]
- id: check-github-workflows
1 change: 1 addition & 0 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,7 @@
# texinfo_no_detailmenu = False

intersphinx_mapping = {
"python": ("https://docs.python.org/", None),
"ipython": ("https://ipython.readthedocs.io/en/stable/", None),
"nbconvert": ("https://nbconvert.readthedocs.io/en/latest/", None),
"nbformat": ("https://nbformat.readthedocs.io/en/latest/", None),
Expand Down
143 changes: 143 additions & 0 deletions docs/source/operators/configuring-logging.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
.. _configurable_logging:

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
:py:func:`logging.config.dictConfig` object. For more information look for
``Application.logging_config`` in :ref:`other-full-config`.


Examples
--------

.. _configurable_logging.jupyter_server:

Jupyter Server
^^^^^^^^^^^^^^

A minimal example which logs Jupyter Server output to a file:

.. code-block:: python
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.


.. _configurable_logging.extension_applications:

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.

.. code-block:: python
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:

.. code-block:: diff
--- 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',
},
},
1 change: 1 addition & 0 deletions docs/source/operators/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ These pages are targeted at people using, configuring, and/or deploying multiple
migrate-from-nbserver
public-server
security
configuring-logging
2 changes: 1 addition & 1 deletion jupyter_server/serverapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -2292,7 +2292,7 @@ def shutdown_no_activity(self):
if len(km) != 0:
return # Kernels still running

if self.extension_manager.any_activity:
if self.extension_manager.any_activity():
return

seconds_since_active = (utcnow() - self.web_app.last_activity()).total_seconds()
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ dependencies = [
"Send2Trash",
"terminado>=0.8.3",
"tornado>=6.2.0",
"traitlets>=5.1",
"traitlets>=5.3.0",
"websocket-client",
"jupyter_events>=0.4.0"
]
Expand Down

0 comments on commit 95b642a

Please sign in to comment.