Skip to content

jsonformatter does not work with Python >= 3.7 #2

@iitsDelbruegger

Description

@iitsDelbruegger

I cannot utilize the jsonformatter to format my logs in Python 3.7 due to a wrong import in jsonformatter.py. The class OrderedDict is imported only for python versions below 3.7.0, but it is utilized in line 72. Am I missing something?

My python version

sys.version_info(major=3, minor=7, micro=4, releaselevel='final', serial=0)

Logging config dict

LOGGING_CONFIG = {
    'version': 1,
    'disable_existing_loggers': False,
    'formatters': {
        'standard': {
            'class': 'jsonformatter.JsonFormatter',
            'format': {"Name": "name", "Levelno": "levelno", "Levelname": "levelname", "Pathname": "pathname",
                       "Filename": "filename", "Module": "module", "Lineno": "lineno", "FuncName": "funcName",
                       "Created": "created", "Asctime": "asctime", "Msecs": "msecs",
                       "RelativeCreated": "relativeCreated", "Thread": "thread", "ThreadName": "threadName",
                       "Process": "process", "Message": "message"}
        },
    },
    'handlers': {
        'default': {
            'level': 'DEBUG',
            'formatter': 'standard',
            'class': 'logging.StreamHandler',
            'stream': 'ext://sys.stdout',  # Default is stderr
        },
    },
    'loggers': {
        '': {  # root logger
            'handlers': ['default'],
            'level': 'INFO',
            'propagate': False
        }
    }
}

The stacktrace:

Traceback (most recent call last):
File "C:\Users\user\AppData\Local\Programs\Python\Python37\lib\logging\config.py", line 542, in configure
formatters[name])
File "C:\Users\user\AppData\Local\Programs\Python\Python37\lib\logging\config.py", line 673, in configure_formatter
result = c(fmt, dfmt, style)
File "C:\Users\user.virtualenvs\cityvolt PlacesService\lib\site-packages\jsonformatter\jsonformatter.py", line 149, in init
self.json_fmt = self.parseFmt(fmt)
File "C:\Users\user.virtualenvs\cityvolt PlacesService\lib\site-packages\jsonformatter\jsonformatter.py", line 72, in parseFmt
elif isinstance(fmt, OrderedDict):
NameError: name 'OrderedDict' is not defined

Metadata

Metadata

Labels

bugSomething isn't working

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions