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
appsettings2which 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 namedappsettings.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.*": {
"level": "WARNING"
},
"urllib3.*": {
"level": "WARNING"
},
"websockets.*": {
"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 8601), 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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file hanaro-0.1.6.tar.gz.
File metadata
- Download URL: hanaro-0.1.6.tar.gz
- Upload date:
- Size: 6.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.3+
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
24577d2d4872aeaee847966514c0ddec795d8ee236844dbfcb851aa331109be6
|
|
| MD5 |
4a404897bafe4ca98e1dfa45530ec358
|
|
| BLAKE2b-256 |
524a8459f6fdb86e2abc379ceb70ef02c1770d3698a73ce732703dec0ab90c71
|
File details
Details for the file hanaro-0.1.6-py3-none-any.whl.
File metadata
- Download URL: hanaro-0.1.6-py3-none-any.whl
- Upload date:
- Size: 7.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.3+
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
eaef9a5d4c39b20b244b9fbd4f13dd568711f997ff170387d327f3fd4e8b4748
|
|
| MD5 |
3baf08ce396eb3efcd00e82aba5f222d
|
|
| BLAKE2b-256 |
bacf4036b46a3243c9e3c7f2b8c4c06faf67c63396514fd108dec2efa5750204
|