Skip to main content

Not-co-logger

Not-co-logger is a simple Python library to help log things to stdout in a specific JSON format. It is inspired by the checkout-logger TypeScript library (https://github.com/CheckoutFinland/checkout-logger).

How to use

This guide is short and in need of much verbosity.

The idea behind this library is that typically in a complex cloud environment it makes ones life much easier if apps log to stdout in a consistent JSON format. This library implements in a pretty simple form some practices that have been found useful.

LogSpan(requestId) creates a logspan object, which has error, warn, info and debug methods to log varying levels of messages. All messages have a type (for example "lambda.handler.start"), message, log group (for example technical or session), and optionally user (could be IP or user id) and meta (free form object).

A good logtype is unique or at least easily greppable. We suggest naming them hierarchically, for example 'component.module.subtask' or something like that. A logtype should be informative but not overly rigid or verbose. Message is the typical human readable part of an event. Meta should be understood as a grab bag object for any additional fields that would be considered useful for the particular log event. For example a HTTP request log event could have the requested path included in the meta object.

All log rows are bound together by the requestId when logging them. Timestamps are automatically added.

Levels

These are suggested guidelines for log levels:

  • Error: The system has run into a fatal exception that requires attention from admins.
  • Warning: Something went wrong, but admins do not need to be urgently alerted.
  • Info: Normal logging.
  • Debug: General developer friendly spam that is wanted in the logs for common "what the hell just happened" type of solving.

Suggested group

Here are some groups that have been found to be useful:

  • request: Incoming requests
  • response: Outgoing responses
  • session: Events related to an active session
  • technical: Events related to some technical state or issues

ExceptionSpan

When you need to log an error but only when an exception is raised, you can use ExceptionSpan context manager:

    with ExceptionSpan('mylog.problem', 'Doing something fails') as log:
        do_something_that_fails()
        log.info('mylog.success', 'It worked!', 'technical')

If do_something_that_fails() fails and raises an exception, the ExceptionSpan logs an error. If the call succeeds, the optional log.info() is called. Note that ExceptionSpan does not catch the exception.

Release files for notcologger 0.2.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for notcologger 0.2.1
File Size Uploaded
notcologger-0.2.1.tar.gz 4.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for notcologger 0.2.1
File Interpreter ABI Platform
notcologger-0.2.1-py3-none-any.whl Python 3 none any Details

Total release size: 9.6 kB

Release files / notcologger-0.2.1.tar.gz

Download URL notcologger-0.2.1.tar.gz
Size 4.4 kB
Tags Source
SHA-256 checksum
How to use checksums
48b206db0951fbed976fccaba1d902ade8a15757d362e31004c30dc09cfa1d06
BLAKE2b-256 checksum
How to use checksums
1e11d0fe7f5604f25435b9ed93c93e16476c4a40c60d2beb9d0816550de41dd9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.2

Release files / notcologger-0.2.1-py3-none-any.whl

Download URL notcologger-0.2.1-py3-none-any.whl
Size 5.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b6eabb615e9572ae295e36aebda989db564c5a8a5792fd7c13d22cf45be19721
BLAKE2b-256 checksum
How to use checksums
0fad50025e667cc3f9e4d5683d587e0ac9db926dc159d070d6739e319a14ff08
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.2

Release history Release notifications | RSS feed

This release

0.2.1 This release

2 release files

0.2.0

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page