Skip to main content

A small package for rerouting gunicorn logs to loguru

Project description

loguricorn

A small package for rerouting gunicorn logs to loguru

Example

This package provides a compatible interface for automatically routing gunicorn logs to the popular loguru library.

Usage

Install the package:

pip install loguricorn

Then pass the custom interface to gunicorn at runtime:

gunicorn --logger-class loguricorn.Logger tests.app:app

All log records will now be routed through the default loguru.logger.

Configuration

It's possible to customize the loguru.logger instance before gunicorn initializes itself. Simply add your changes in a configuration file and pass it to gunicorn at runtime:

import sys

from loguru import logger

logger.remove()
logger.add(
    sys.stderr,
    colorize=True,
    format="<green>{time}</green> <level>{message}</level>",
)
gunicorn -c conf.py --logger-class loguricorn.Logger tests.app:app

It's recommended to import any customizations from your main application and use them in the configuration in order to obtain a consistent log record format across the entire execution.

Testing

Testing is done by starting gunicorn in a subprocess with the custom logger enabled and validating that the emitted logs match the expected format.

Install dev dependencies:

poetry install

Run test:

poetry run tox .

Contributing

Check out the issues for items needing attention or submit your own and then:

  1. Fork the repo
  2. Create your feature branch (git checkout -b feature/fooBar)
  3. Commit your changes (git commit -am 'Add some fooBar')
  4. Push to the branch (git push origin feature/fooBar)
  5. Create a new Pull Request

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

loguricorn-0.1.0.tar.gz (3.8 kB view hashes)

Uploaded Source

Built Distribution

loguricorn-0.1.0-py3-none-any.whl (4.0 kB view hashes)

Uploaded Python 3

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