Skip to main content

JSON structured logger

Project description

JamSuite Logger

                                                 
                                                 
   ██  ▄▄▄  ▄▄   ▄▄ ▄█████ ▄▄ ▄▄ ▄▄ ▄▄▄▄▄▄ ▄▄▄▄▄ 
   ██ ██▀██ ██▀▄▀██ ▀▀▀▄▄▄ ██ ██ ██   ██   ██▄▄  
████▀ ██▀██ ██   ██ █████▀ ▀███▀ ██   ██   ██▄▄▄ 
                          .                  
                          |    _  _  _  _ ._.
                          |___(_)(_](_](/,[  
                                 ._|._|                              

Structured JSON Logging for Python

Logging convention

JamSuite Logger provides a JSONFormatter that converts the log message to JSON. If the message is a simple string, it gets set as the message attribute inside the log message.

Standard attributes

JamSuite's JSONFormatter will add attributes that start with the log_ prefix to each message including the timestamp, source file, and level.

String messages logged as JSON

>>> log.info("just log a string")
{
  "log_time": "2025-12-14 10:13:33,989",
  "log_source": "__main__",
  "log_level": "INFO",
  "message": "just log a string"
}

Dictionaries logged as JSON

Most commonly, you'll use dictionaries to represent the log message.

>>> log.info({"message":"Hey Ma, look at me!","user":"Your Kid!"})
{
  "log_time": "2025-12-14 10:11:31,177",
  "log_source": "__main__",
  "log_level": "INFO",
  "message": "Hey Ma, look at me!",
  "user": "Your Kid!"
}

Exception Logging

If you put an exception inside the message its message will get added to the JSON log message.

>>> e = Exception("woah there!")
>>> log.info(e)
{
  "log_time": "2025-12-14 10:15:38,324",
  "log_source": "__main__",
  "log_level": "INFO",
  "message": "woah there!"
}

To capture exception information, set exc_info kwarg as you would in Python logging.

>>> try:
...     raise(Exception("woah there!"))
... except Exception as e:
...     log.error("Caught exception in try block", exc_info=e)
... 
{
  "log_time": "2025-12-14 10:18:06,249",
  "log_source": "__main__",
  "log_level": "ERROR",
  "message": "Caught exception in try block",
  "log_exception": "Exception(woah there!)",
  "log_traceback": [
    "<stdin> line 2 in <module>: "
  ]
}

Project details


Download files

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

Source Distribution

jamsuite_logger-0.9.0.tar.gz (116.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

jamsuite_logger-0.9.0-py3-none-any.whl (14.0 kB view details)

Uploaded Python 3

File details

Details for the file jamsuite_logger-0.9.0.tar.gz.

File metadata

  • Download URL: jamsuite_logger-0.9.0.tar.gz
  • Upload date:
  • Size: 116.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.11

File hashes

Hashes for jamsuite_logger-0.9.0.tar.gz
Algorithm Hash digest
SHA256 0468cd54b7a26a1d8fcef3844ce90d11ea62c66485126622c7d35901a2d2730f
MD5 d1a835fe4e6f69283c3aa1b23b9c296e
BLAKE2b-256 547692e20e07c430f3f24b94b1d02faf82511f5a1eab63fc3b709e2a54a8cdbf

See more details on using hashes here.

File details

Details for the file jamsuite_logger-0.9.0-py3-none-any.whl.

File metadata

File hashes

Hashes for jamsuite_logger-0.9.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1410a251ce7f377e3cd79016053da0f4b39c4e03e8d07c72f927dfc0cd4e0eda
MD5 042e38964e058c373ad5e28cb885b0fb
BLAKE2b-256 64f4415df236ace085b44c076a67f6a56dd3e3aaac2ba39f1f7493b18bb8b146

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page