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
Built Distribution
File details
Details for the file notcologger-0.2.0.tar.gz
.
File metadata
- Download URL: notcologger-0.2.0.tar.gz
- Upload date:
- Size: 4.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | cb4c1701b08a1a2cec27359d8687b5f64db140501439958a48c002242087ff46 |
|
MD5 | 61c888f135d4e453229639cee0d6512f |
|
BLAKE2b-256 | f4698a68271e0d900e180725dc4caa46fc5d5992579ec10537a16e9cfcb1a300 |
File details
Details for the file notcologger-0.2.0-py3-none-any.whl
.
File metadata
- Download URL: notcologger-0.2.0-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
Algorithm | Hash digest | |
---|---|---|
SHA256 | ee35a855df33a859d8ee2042def18d8f01d8d639146e801c0f84e8f355e7761c |
|
MD5 | 0ce8c04c7843a56ad40e463e75288140 |
|
BLAKE2b-256 | df446d5d2ebb63b34f6a594e6cef72f7c0b5db099a652508b78224eac7be85de |