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.3.1.tar.gz
(15.4 kB
view details)
Built Distribution
pylogg-0.3.1-py3-none-any.whl
(14.6 kB
view details)
File details
Details for the file pylogg-0.3.1.tar.gz
.
File metadata
- Download URL: pylogg-0.3.1.tar.gz
- Upload date:
- Size: 15.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.9.19
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c714e08567c22f3a37786b2b65d18fa962e652f9aebfe0ebd9b7edabb4ab930b |
|
MD5 | 6e149ce69e5ae2d9d9dae6b9172f24f1 |
|
BLAKE2b-256 | 702318bac1dbd74550140f46c7d5059ffbf529024db88381417dc907763ca964 |
File details
Details for the file pylogg-0.3.1-py3-none-any.whl
.
File metadata
- Download URL: pylogg-0.3.1-py3-none-any.whl
- Upload date:
- Size: 14.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.9.19
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f3c905533631614defdce8e8e7da504af64ac3f60db69cefa713927fd207f4f4 |
|
MD5 | bf60b269f4be7fee56dd81d5fe9e90db |
|
BLAKE2b-256 | 7a992dea7ea7067355ef3995fb5d264c61c5381aa0904ec7ed35c5e40f6e8df5 |