Skip to content

Commit

Permalink
Consistent logging method (#607)
Browse files Browse the repository at this point in the history
* Remove direct use of logging to keep log format consistent

* Add missing log for failed server info file deletion
* Add missing null check
* Remove unused import: logging
  • Loading branch information
mwakaba2 authored Nov 6, 2021
1 parent 3ecb4e0 commit a1b013e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
11 changes: 6 additions & 5 deletions jupyter_server/serverapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,7 @@ def _maybe_remove_unix_socket(socket_path):
pass

def start(self):
servers = list(list_running_servers(self.runtime_dir))
servers = list(list_running_servers(self.runtime_dir, log=self.log))
if not servers:
self.exit("There are no running servers (per %s)" % self.runtime_dir)
for server in servers:
Expand Down Expand Up @@ -619,7 +619,7 @@ class JupyterServerListApp(JupyterApp):
)

def start(self):
serverinfo_list = list(list_running_servers(self.runtime_dir))
serverinfo_list = list(list_running_servers(self.runtime_dir, log=self.log))
if self.jsonlist:
print(json.dumps(serverinfo_list, indent=2))
elif self.json:
Expand Down Expand Up @@ -2682,7 +2682,7 @@ def stop(self, from_signal=False):
self.io_loop.add_callback(self._stop)


def list_running_servers(runtime_dir=None):
def list_running_servers(runtime_dir=None, log=None):
"""Iterate over the server info files of running Jupyter servers.
Given a runtime directory, find jpserver-* files in the security directory,
Expand All @@ -2709,8 +2709,9 @@ def list_running_servers(runtime_dir=None):
# If the process has died, try to delete its info file
try:
os.unlink(os.path.join(runtime_dir, file_name))
except OSError:
pass # TODO: This should warn or log or something
except OSError as e:
if log:
log.warning(_i18n("Deleting server info file failed: %s.") % e)


# -----------------------------------------------------------------------------
Expand Down
5 changes: 2 additions & 3 deletions jupyter_server/services/kernels/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
# Copyright (c) Jupyter Development Team.
# Distributed under the terms of the Modified BSD License.
import json
import logging
from textwrap import dedent

from ipython_genutils.py3compat import cast_unicode
Expand Down Expand Up @@ -624,11 +623,11 @@ def _send_status_message(self, status):
self.write_message(json.dumps(msg, default=json_default))

def on_kernel_restarted(self):
logging.warn("kernel %s restarted", self.kernel_id)
self.log.warning("kernel %s restarted", self.kernel_id)
self._send_status_message("restarting")

def on_restart_failed(self):
logging.error("kernel %s restarted failed!", self.kernel_id)
self.log.error("kernel %s restarted failed!", self.kernel_id)
self._send_status_message("dead")

def _on_error(self, msg):
Expand Down

0 comments on commit a1b013e

Please sign in to comment.