Logging made simple.
Project description
logpie
Logging made simple.
This is a simple logging module with thread & file locking abilities.
Installation:
python -m pip install [--upgrade] logpie
Usage:
# your `main.py` module
from os.path import dirname, realpath, join
from sys import modules
from types import ModuleType
from cfgpie import get_config, CfgParser
from logpie import get_logger, Logger
# **************************** config constants: **************************** #
# main module
MODULE: ModuleType = modules.get("__main__")
# root directory
ROOT: str = dirname(realpath(MODULE.__file__))
# default config file path:
CONFIG: str = join(ROOT, "config", "cfgpie.ini")
# backup config params:
BACKUP: dict = {
"LOGGER": {
"basename": "logpie", # if handler is `file`
"folder": r"${DEFAULT:directory}\logs",
"handler": "file", # or `console` or `nostream` (no output)
"debug": True, # if set to `True` it will also print `DEBUG` messages
}
}
# NOTE: The constants above serve the usage example
# and you can use whatever suits you best.
# ********************** get `ConfigParser` instance: *********************** #
cfg: CfgParser = get_config(name="my_config")
cfg.set_defaults(directory=ROOT)
cfg.open(file_path=CONFIG, encoding="UTF-8", fallback=BACKUP)
# ************************* get `Logger` instance: ************************** #
log: Logger = get_logger(name="my_logger", config=cfg)
# we can pass a config instance
or
log: Logger = get_logger(name="my_logger", config="my_config")
# it will look for a config instance named `my_config`
or
log: Logger = get_logger(name="my_logger", basename="logpie", handler="file", debug=True)
# it will create and use its own config instance
log.debug("Testing debug messages...")
log.info("Testing info messages...")
log.warning("Testing warning messages...")
log.error("Testing error messages...")
log.critical("Testing critical messages...")
By default, debugging is set to False and must be enabled to work.
The log file is prefixed with a date and will have an index number attached before the extension (ex: 2022-08-01_logpie.1.log
).
When it reaches 1 Mb
the file handler will switch to another file by incrementing its index with 1
.
The folder tree is by default structured as follows:
.
└───logs
└───year (ex: 2022)
└───month (ex: january)
├───2022-08-01_logpie.1.log
├───2022-08-01_logpie.2.log
└───2022-08-01_logpie.3.log
When the current month changes, a new folder is created and the previous one is archived.
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
File details
Details for the file logpie-1.0.1.tar.gz
.
File metadata
- Download URL: logpie-1.0.1.tar.gz
- Upload date:
- Size: 8.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c5f3c1d5f45c917a62c1241b315b6a604d0fd877eba854c0a577a23d11407645 |
|
MD5 | 8970822edaed3eb90233735244141b12 |
|
BLAKE2b-256 | 3d6d75b92f1889871177286b9900292c47f46be6e92240d8bfee02c9c7dc212a |
File details
Details for the file logpie-1.0.1-py3-none-any.whl
.
File metadata
- Download URL: logpie-1.0.1-py3-none-any.whl
- Upload date:
- Size: 8.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f64888ff138c3b322b371df8f5887dae4a2c326c91c7321d3043db1c4b9775bb |
|
MD5 | 03505295fcbd5c7bc1bc7475283b7897 |
|
BLAKE2b-256 | d4d2d5e0be2331cb8047155d7d039cbd5d0d90ef07e3ae433dce4e17197d72c5 |