Skip to main content

..a non-invasive `logging` configurator.

Project description

hanaro (하나로) is a non-invasive logging configurator.

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:

import hanaro

hanaro.configure_logging()
logger = hanaro.get_logger()
logger.info('Hello, World!')

In the above example hanaro is used to apply a basic logging configuration and then create a Logger instance that identifies the current module. No explciit configuration is provided, so the default behavior is to allocate a console handler with a logfmt that allows logging back-ends (GTM, ELK, etc) to properly handle mult-line log entries (typically error logs containing stack traces.)

When executed the program outputs the following:

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

Configuration

Configuration handling is performed using appsettings2 which supports json, toml, yaml, environment variable, and command-line args to provide a unified configuration. For demonstration, assume the following is the content of appsettings.json:

{
    "logging": {
        "level": "INFO",
        "format": "[%(asctime)s] %(message)s level=%(levelname)s source=%(name)s %(metadata)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\" %(metadata)s"
            },
            {
                "type": "custom",
                "class": "myapp.mymodule.myhandler",
                "level": "WARNING",
                "format": "msg=\"%(message)s\" level=\"%(levelname)s\" source=\"%(name)s\" func=\"%(funcName)s\" %(metadata)s"
            }
        ],
        "filters": {
            "asyncio": {
                "level": "WARNING"
            },
            "mysql.*": {
                "level": "WARNING"
            },
            "urllib3.*": {
                "level": "WARNING"
            },
            "websockets.*": {
                "level": "WARNING"
            }
        }
    }
}

Modifying the prior example to use such a configuration is trivial:

import appsettings2
import hanaro

hanaro.configure_logging(
    appsettings2.get_configuration()
)
logger = hanaro.get_logger()
logger.info('Hello, World!')

QA and DevOps will find that appsettings2.get_configuration makes it very easy to override configuration with just the one line of code.

Notables..

Things not obvious given the example above:

  • All configuration options are optional, you can reduce the config to specify only the features you wish to customize.
  • If no configuration (or a partial configuration) is provided, configure_logging() will apply defaults.
  • If no handlers are configured, a default handler for "console" logging is configured.
  • If no format is specified, a default that is friendly toward GTM/ELK/etc parsing is used.
  • 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-1.3.0.tar.gz (14.3 kB view details)

Uploaded Source

Built Distribution

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

hanaro-1.3.0-py3-none-any.whl (15.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: hanaro-1.3.0.tar.gz
  • Upload date:
  • Size: 14.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.15+

File hashes

Hashes for hanaro-1.3.0.tar.gz
Algorithm Hash digest
SHA256 bac9d34d9b32ce1e43d1a23203c719dc392839c20ae5d0d237586aa49e6601b9
MD5 76c5c465d4fa785982d3e4191242b154
BLAKE2b-256 93c9cb5859bfb4e3f6ca2d240b7933bf3ff8e16a4d0f134510a622a569a23245

See more details on using hashes here.

File details

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

File metadata

  • Download URL: hanaro-1.3.0-py3-none-any.whl
  • Upload date:
  • Size: 15.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.15+

File hashes

Hashes for hanaro-1.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e8d6e0499b625a81f9c28ef3de286da93237e25a770d4781e3b48883fcfcab8d
MD5 7f85ed4ff6e569a27ae4bb9f36f3fb45
BLAKE2b-256 61496f1a0897f4db89d3fb17485afede0b1e2e82eaf3a5f431eb177ce742ada9

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