Skip to main content

Not CO Logger, a cloud logging library.

Project description

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.

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

notcologger-0.2.1.tar.gz (4.4 kB view details)

Uploaded Source

Built Distribution

notcologger-0.2.1-py3-none-any.whl (5.2 kB view details)

Uploaded Python 3

File details

Details for the file notcologger-0.2.1.tar.gz.

File metadata

  • Download URL: notcologger-0.2.1.tar.gz
  • Upload date:
  • Size: 4.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.2

File hashes

Hashes for notcologger-0.2.1.tar.gz
Algorithm Hash digest
SHA256 48b206db0951fbed976fccaba1d902ade8a15757d362e31004c30dc09cfa1d06
MD5 7a8af9a63048dcab152a3102ae28ff1e
BLAKE2b-256 1e11d0fe7f5604f25435b9ed93c93e16476c4a40c60d2beb9d0816550de41dd9

See more details on using hashes here.

File details

Details for the file notcologger-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: notcologger-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 5.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.2

File hashes

Hashes for notcologger-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 b6eabb615e9572ae295e36aebda989db564c5a8a5792fd7c13d22cf45be19721
MD5 93d834801a795eefad9312d2ccdd8be5
BLAKE2b-256 0fad50025e667cc3f9e4d5683d587e0ac9db926dc159d070d6739e319a14ff08

See more details on using hashes here.

Supported by

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