Skip to content

Commit 9c364fe

Browse files
committed
[FIX] logging_json: forward compatibility
Make the module compatible w/ ``python-json-logger==3.3.*`` (importing ``jsonlogger`` displays a deprecation warning)
1 parent fdbf1b4 commit 9c364fe

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

logging_json/json_log.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,23 @@
66
import threading
77
import uuid
88

9+
import pythonjsonlogger
10+
911
from odoo import http
1012

1113
from .strtobool import strtobool
1214

1315
_logger = logging.getLogger(__name__)
1416

15-
try:
16-
from pythonjsonlogger import jsonlogger
17-
except ImportError:
17+
# Module ``jsonlogger`` of package ``python-json-logger`` is deprecated since version
18+
# 3.1.0, keep it for backward compatibility
19+
if hasattr(pythonjsonlogger, "json"):
20+
jsonlogger = pythonjsonlogger.json
21+
elif hasattr(pythonjsonlogger, "jsonlogger"):
22+
jsonlogger = pythonjsonlogger.jsonlogger
23+
else:
1824
jsonlogger = None # noqa
19-
_logger.debug("Cannot 'import pythonjsonlogger'.")
25+
_logger.debug("Cannot import 'json' or 'jsonlogger' from 'pythonjsonlogger'.")
2026

2127

2228
def is_true(strval):

0 commit comments

Comments
 (0)