Personally opinionated logger in Python.
Project description
python-logg
A personally opinionated logging package in Python.
Features:
- Colors in console.
- Saving log messages into a single file.
- Support for named sub-loggers.
- Override of log levels and settings from the main function.
- Eight levels of verbosity.
- Wrapping and shortening of long messages.
- Automatic logging of elapsed times for long processes.
Installation
Clone this repo and install with pip
.
git clone https://github.com/akhlakm/python-logg.git
cd python-logg
pip install -e .
Usage
Set up the logger in the main script. These settings will override the settings set using pylogg.New()
instance.
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 a new sub-logger
log = pylogg.New('module')
# 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 New
.
See the examples for more details.
About
LICENSE MIT Copyright 2023 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.1.16.tar.gz
(7.0 kB
view details)
Built Distribution
File details
Details for the file pylogg-0.1.16.tar.gz
.
File metadata
- Download URL: pylogg-0.1.16.tar.gz
- Upload date:
- Size: 7.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.9.18
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0c2213dfaa13b713ffe1a1df51d5cd344e56a6ddbebc31895f6f11e237c24318 |
|
MD5 | 30c492ab56a913d13ac97cc656984a2f |
|
BLAKE2b-256 | 5a5e81b25f434bb7e47bfb5f54e99e3baba57317d607471d41120f76a3799abc |
File details
Details for the file pylogg-0.1.16-py3-none-any.whl
.
File metadata
- Download URL: pylogg-0.1.16-py3-none-any.whl
- Upload date:
- Size: 7.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.9.18
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 615b6c068597248a372e320a87c1f019fa22ef73f9dcde7e7cac54ff7b2c1c6b |
|
MD5 | a4e82c1ad45e7df79262a91bef9f561d |
|
BLAKE2b-256 | 117ef82ff7e5721250220532faa41f030cadc679bf5d8705c52d6a6a4ce96323 |