Skip to content

Commit

Permalink
Fix DeprecationWarning with patched python-json-logger
Browse files Browse the repository at this point in the history
Running tests with https://github.com/nhairs/python-json-logger 3.1.0
produces:

  DeprecationWarning: pythonjsonlogger.jsonlogger has been moved to pythonjsonlogger.json

It's easy enough to be compatible with both.
  • Loading branch information
cjwatson committed Nov 5, 2024
1 parent 08ff0b9 commit 24e7160
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions jupyter_events/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 24e7160

Please sign in to comment.