Logging and YAML-based configuration modules in Python.
Project description
PyLogg
Logging and YAML-based configuration modules in Python.
Installation
You can install this package from PyPI with pip
.
pip install -U pylogg
Usage
Set up the logger in the main script.
import pylogg
pylogg.init(pylogg.Level.TRACE, colored=False)
pylogg.info("Hello world.")
Update individual settings if needed. These settings will override the settings set using pylogg.get()
instances.
import pylogg as log
# Set output file
log.setFile(open("test.log", "w+"))
# Show date and times on console
log.setConsoleTimes(show=True)
# Save date and times to file
log.setFileTimes(show=True)
# Set global logging level
log.setLevel(log.DEBUG)
# Override the level of a named sub-logger
log.setLoggerLevel('module', log.INFO)
# Use
log.info("Hello world")
# Close the log file
log.close()
Use sub-logger from the modules.
import time
import pylogg
# Create or get a named sub-logger.
log = pylogg.get(__name__)
# Use
def run():
log.Trace("Running module ...")
# Support for f strings.
log.Debug("2 + 2 = {} ({answer})", 2 + 2, answer=True)
def timing():
# Get the timer instance
t1 = log.Info("Started process ...")
# long process
time.sleep(2)
# Call timer.done() to log elapsed time.
t1.done("Process completed.")
Note: Full logg package must be imported. Use import pylogg
,
do not use from pylogg import get
.
See the examples for more details.
Development
# Create a fork and clone the git repo.
git clone https://github.com/akhlakm/python-logg.git
cd python-logg
# Install dev requirements.
pip install -e .[dev]
# Install pre-commit git hooks.
pre-commit install
# Make changes and commit.
# Bump the version
./make.sh bump
# Publish new tag.
./make.sh publish
About
LICENSE MIT Copyright 2024 Akhlak Mahmood
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
pylogg-0.4.1.tar.gz
(15.5 kB
view details)
Built Distribution
pylogg-0.4.1-py3-none-any.whl
(14.8 kB
view details)
File details
Details for the file pylogg-0.4.1.tar.gz
.
File metadata
- Download URL: pylogg-0.4.1.tar.gz
- Upload date:
- Size: 15.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.9.20
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 162daaebb5b9d5633eb0b8b7fe3d677dacc3da523f49f015ed05d2cd8206074f |
|
MD5 | a601a58c9b9ffa22fd727d29599bec99 |
|
BLAKE2b-256 | a4a6cae7cf4b3e2b57e8f986937b3b320de999af234049645febdb7979ad7459 |
File details
Details for the file pylogg-0.4.1-py3-none-any.whl
.
File metadata
- Download URL: pylogg-0.4.1-py3-none-any.whl
- Upload date:
- Size: 14.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.9.20
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 380aa683120ab7488fa231d40472ba747bfcfe7d9fe8ef035681b3586b0a1b9d |
|
MD5 | 1c0ae24a07eeb70630ae123d8792acce |
|
BLAKE2b-256 | 3e0d40e65ffb1e7c2ec6eb900ed7cfe4ab654fe5ca22d5d07c846126e8945f06 |