Skip to main content

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

  1. Install this package with optional extras:

    pip install python-logsy[fluent,sentry]
    
  2. 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 the fluent dependencies to be installed via the optional extras. Furthermore, the file handler uses logging.handlers.RotatingFileHandler. Log files will rollover at 100 megabytes when using the file 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',
    )
    
  3. 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
        },
    )
    
  4. Log as per usual:

    import logging
    
    logger = logging.getLogger(__name__)
    logger.info('Testing')
    
  5. 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


Download files

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

Source Distribution

python_logsy-0.1.1.tar.gz (4.9 kB view details)

Uploaded Source

Built Distribution

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

python_logsy-0.1.1-py3-none-any.whl (4.7 kB view details)

Uploaded Python 3

File details

Details for the file python_logsy-0.1.1.tar.gz.

File metadata

  • Download URL: python_logsy-0.1.1.tar.gz
  • Upload date:
  • Size: 4.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.6

File hashes

Hashes for python_logsy-0.1.1.tar.gz
Algorithm Hash digest
SHA256 474a50584f85eafdd90e23822f4ca292a18f3cee4698f9e6b79dd372e1dd1aac
MD5 88fc5b0f33337a5c9a82af47fd4f4738
BLAKE2b-256 2c4c7326b1171671c96b5e977d9f950390ea6303c8c7001d225bad90c2e4b4ea

See more details on using hashes here.

File details

Details for the file python_logsy-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: python_logsy-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 4.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.6

File hashes

Hashes for python_logsy-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 c7277b7715c22b114e7f527552883038d533fad41bc167aef2a718ba233b265f
MD5 e8e5528e300503bb4351c09001f7768c
BLAKE2b-256 3044c3140a6bb707f7c5330d60849f78e1b7521734d8c2c78768421cacd18d69

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