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.0.tar.gz
(15.5 kB
view details)
Built Distribution
pylogg-0.4.0-py3-none-any.whl
(14.8 kB
view details)
File details
Details for the file pylogg-0.4.0.tar.gz
.
File metadata
- Download URL: pylogg-0.4.0.tar.gz
- Upload date:
- Size: 15.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.9.19
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a0a0c698f118d4b5fcc3a2018476390cd48fb98ad9cbe4eca5941490ff38d5a6 |
|
MD5 | 9b3322d4b75d502782390ffa10994d9a |
|
BLAKE2b-256 | 666d676e71e56764b7f76607f6000cc0957a740c8be4b458f0372b49d9579580 |
File details
Details for the file pylogg-0.4.0-py3-none-any.whl
.
File metadata
- Download URL: pylogg-0.4.0-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.19
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 81a23156bda19e7996320d399870a6311f9c131fcd3f153ce2e6c5c1b6b7df06 |
|
MD5 | 5f0b5fc16e71e324b011a0513834640e |
|
BLAKE2b-256 | 2d7be4db0e8c80b6a398dbcc986c737aacb4979576005885193d1c499596d662 |