Skip to main content

Python logging module outputs logs as JSON.

Project description


GitHub Workflow Status GitHub release (latest by date including pre-releases) PyPI - Python Version GitHub

Python logging outputs as JSON.
This JsonFormatter is written in Pure Python.


pip install json-pyformatter


import logging
from json_pyformmatter import JsonFormatter

logger = logging.getLogger(__name__)
handler = logging.StreamHandler()
fields = ('levelname', 'filename', 'message')

default fields is ('asctime', 'levelname', 'message')
Other supported fields are:

field name description
name Name of the logger (logging channel)
levelno Numeric logging level for the message
levelname Text logging level for the message
pathname Full pathname of the source file where the logging call was issued
filename Filename portion of pathname
module Module (name portion of filename)
lineno Source line number where the logging call was issued
funcName Function name
created Time when the LogRecord was created (time.time()return value)
asctime Textual time when the LogRecord was created
msecs Millisecond portion of the creation time
relativeCreated Time in milliseconds when the LogRecord was created, relative to the time the logging module was loaded (typically at application startup time)
thread Thread ID
threadName Thread name
process Process ID
message The result of record.getMessage(), computed just as the record is emitted

In details, please refere to logrecord-attributes


{"levelname": "INFO", "filename": "", "message": "hello"}

If specify indent option as 2, the result is as follows:

  "levelname": "INFO",
  "filename": "",
  "message": "hello"

When exc_info is True, the result includes traceback infomation as follows:

  'asctime': '2019-12-01 13:58:34',
  'levelname': 'ERROR',
  'message': 'error occurred !!',
  'traceback': [
    'Traceback (most rec...ll last):',
    'File "/example/test..._exc_info',
    'raise TypeError(message)',
    'TypeError: error occurred !!'

Logging message type is dict:

  'asctime': '2019-12-01 23:34:32',
  'levelname': 'INFO',
  'message': {
    'id': '001',
    'msg': 'This is test.',
    'name': 'test'

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for json-pyformatter, version 0.1.0
Filename, size File type Python version Upload date Hashes
Filename, size json_pyformatter-0.1.0-py3-none-any.whl (4.8 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size json-pyformatter-0.1.0.tar.gz (4.6 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page