Skip to main content

A non-invasive `logging` configurator and facilitator.

Project description

hanaro (하나로) is a non-invasive logging configurator and facilitator for Python.

This README is only a high-level introduction to hanaro. For more detailed documentation, please view the official docs at https://hanaro.readthedocs.io.

Installation

hanaro can be installed from pypi through the usual means:

pip install hanaro

Usage

Let's try a "learn by example" approach. The following two snippets are the contents of a configuration file that contains a "logging" configuration section, and a Python code file that initializes Python's standard logging system using that configuration. This is by no means an exhaustive example, it only intends to touch on the major offerings of hanaro.

NOTE: Configuration handling is performed using appsettings2 which supports json, toml, yaml, xml, command-line args, and environment variables to provide a unified configuration solution. This example, however, uses json because of json's wider familiarity. For the sake of demonstration assume this content is in a file named appsettings.json.

{
    "logging": {
        "level": "INFO",
        "format": "[%(asctime)s] %(message)s level=%(levelname)s source=%(name)s %(meta)s",
        "datefmt": "%Y-%m-%dT%H:%M:%S",
        "handlers": [
            {
                "type": "console",
                "level": "DEBUG"
            },
            {
                "type": "file",
                "level": "DEBUG",
                "path": "logs/",
                "name": "debug.log",
                "max_size": "4KiB",
                "max_count": 10,
                "format": "[%(asctime)s] level=%(levelname)s %(message)s source=\"%(name)s\" func=\"%(funcName)s\" %(meta)s"
            },
            {
                "type": "custom",
                "canonical": "myapp.mymodule.myhandler",
                "level": "WARNING",
                "format": "msg=\"%(message)s\" level=\"%(levelname)s\" source=\"%(name)s\" func=\"%(funcName)s\" %(meta)s"
            }
        ],
        "filters": {
            "asyncio": {
                "level": "WARNING"
            },
            "mysql.connector": {
                "level": "WARNING"
            },
            "urllib3.connectionpool": {
                "level": "WARNING"
            },
            "websockets.client": {
                "level": "WARNING"
            }
        }
    },
}

This code sample is a minimum-viable solution. The custom handler above is omitted, but for the sake of demonstration know that canonical is the fully-qualified type name of a logging.Handler subclass and hanaro will create an instance of that class and configure as it does all other handlers.

from appsettings2 import getConfiguration
from hanaro import configureLogging
import logging

configureLogging(getConfiguration())

logger = logging.getLogger(__name__)

logger.info('Hello, World!')

When executed the program outputs the following:

[2025-12-31T12:34:56] Hello, World! level=INFO source=__main__ 

Notables..

Things not obvious given the example above:

  • All configuration options are optional, you can reduce the config to specifying only those things you wish to customize.
  • It is not necessary to load a configuration at all, a call to configureLogging() will still apply reasonable defaults such as adding a console handler, applying a line format, applying a default date format (ISO 9601), etc.
  • If no handlers are configured, a default handler for "console" is configured.

hanaro only has a single direct dependency: appsettings2.

Contact

You can reach me on Discord or open an Issue on Github.

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

hanaro-0.0.2.tar.gz (5.8 kB view details)

Uploaded Source

Built Distribution

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

hanaro-0.0.2-py3-none-any.whl (7.2 kB view details)

Uploaded Python 3

File details

Details for the file hanaro-0.0.2.tar.gz.

File metadata

  • Download URL: hanaro-0.0.2.tar.gz
  • Upload date:
  • Size: 5.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.3+

File hashes

Hashes for hanaro-0.0.2.tar.gz
Algorithm Hash digest
SHA256 953055485c6cd8f768ee369ec7fe3d121d537c03f4b6d094045a19085a3e5036
MD5 bdcaf734dfabae2157a1cf31521b692e
BLAKE2b-256 6f4f95f4ec779c98e3a9c0977f3fcfaf9253e1e5f2148378fe2f5a902899358c

See more details on using hashes here.

File details

Details for the file hanaro-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: hanaro-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 7.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.3+

File hashes

Hashes for hanaro-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 725ad234a25bc1ecf8717ff92397b2fcc6a76151be06e0f12a5f885a85e87b6f
MD5 06901bae0d83e7f2d510ddd63eee84be
BLAKE2b-256 adfc5b2f756a2ec44f9926cfb3b54747dad508019a4d4ad41e080271ce06e7d5

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