Skip to main content

Defines a mixin class that adds a convenient get_logger method.

Project description

logmixin

Description

This is an extremely small Python package (one module, ~40 lines) to enable quick and easy logging within class methods.

Usage

It defines a mixin class that adds a get_logger method to your class. This method returns a logger with the name of your module, class, and method that called it. For example, suppose you have a module called my_module.py with these contents:

import logging
from logmixin import LogMixin


class MyClass(LogMixin):
    """A class with logging enabled."""
    def my_method(self):
        self.get_logger().info("Hello, world!")


if __name__ == "__main__":
    logging.basicConfig(level=logging.INFO)
    MyClass().my_method()

If you run this file, you will see the following output:

INFO:my_module.MyClass.my_method:Hello, world!

Installation

You can install this package from PyPI:

pip install logmixin

License

MIT

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

logmixin-0.1.4.tar.gz (3.0 kB view hashes)

Uploaded Source

Built Distribution

logmixin-0.1.4-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