diff --git a/jupyter_events/logger.py b/jupyter_events/logger.py index 8cc1fba..d002d0c 100644 --- a/jupyter_events/logger.py +++ b/jupyter_events/logger.py @@ -12,7 +12,10 @@ from datetime import datetime, timezone from jsonschema import ValidationError -from pythonjsonlogger import jsonlogger +try: + from pythonjsonlogger.json import JsonFormatter +except ImportError: + from pythonjsonlogger.jsonlogger import JsonFormatter from traitlets import Dict, Instance, Set, default from traitlets.config import Config, LoggingConfigurable @@ -171,7 +174,7 @@ def _handle_message_field(record: t.Any, **kwargs: t.Any) -> str: del record["message"] return json.dumps(record, **kwargs) - formatter = jsonlogger.JsonFormatter( # type:ignore [no-untyped-call] + formatter = JsonFormatter( # type:ignore [no-untyped-call] json_serializer=_handle_message_field, ) handler.setFormatter(formatter)