A standardised logging configuration I use for a few things.
Project description
python-logsy
A standardised logging configuration I use for a few things.
Quickstart
-
Install this package with optional extras:
pip install python-logsy[fluent,sentry]
-
Import and configure. This package has three logging handlers available in the default configuration. All are relatively self-explanatory except that the
fluent
handler logs to a Fluentd or Fluent Bit instance and requires thefluent
dependencies to be installed via the optional extras. Furthermore, thefile
handler useslogging.handlers.RotatingFileHandler
. Log files will rollover at 100 megabytes when using thefile
handler.import logging import logsy config = { 'loggers': { 'app': { 'handlers': ['console', 'fluent', 'file'], 'level': 'INFO', 'propagate': True, }, }, } logsy.init( config, tag='apps.myapp', # Also used as the Fluent tag (routing) fluent_host='localhost', environment='production', release='2.1.1-beta', )
-
A complete example of
init
; including setup for Sentry:logsy.init( config, tag='apps.myapp', # Also used as the Fluent tag (routing) replace_config=False, fluent_host='localhost', fluent_port=24224, # default async_fluent=True, # default environment='debug', debug=True, # default is False release='2.1.1-beta', level=logging.INFO, # default sentry_config={ 'dsn': 'fake-dsn-string', 'traces_sample_rate': 1.0, # default }, )
-
Log as per usual:
import logging logger = logging.getLogger(__name__) logger.info('Testing')
-
If needed, replace the default logging config with your own:
config = { 'version': 1, 'disable_existing_loggers': False, 'formatters': {}, # incomplete 'handlers': {}, # incomplete } logsy.init( config, replace_config=True, tag='apps.myapp', fluent_host='localhost', fluent_port=24224, # default environment='debug', debug=True, # default is False release='2.1.1-beta', level=logging.INFO, # default )
Project details
Release history Release notifications | RSS feed
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 python-logsy-0.1.0.tar.gz
.
File metadata
- Download URL: python-logsy-0.1.0.tar.gz
- Upload date:
- Size: 4.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.11.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8cd9b3f0a0b72463415bba37994df9351e946047559e2e0aa5af338d4f5a3454 |
|
MD5 | c39b5421ad26bf9932f8f0d591461b6b |
|
BLAKE2b-256 | 6c22ff77be0f7b89846430b004cd5b28d1d53152ff42be3bbbe4fbe89a6bffa1 |
File details
Details for the file python_logsy-0.1.0-py3-none-any.whl
.
File metadata
- Download URL: python_logsy-0.1.0-py3-none-any.whl
- Upload date:
- Size: 4.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.11.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9320bae8c107db029063840f7b2f7bda635c218987345cf05da7875fc45cbd42 |
|
MD5 | e308503b035ba0bbfdbda82bf92b1758 |
|
BLAKE2b-256 | 75fd4c511898416bb9c5bf16a685f8e28f9e8f3705fb774c75b083363e19fde8 |