Skip to main content

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


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.2.0.tar.gz (15.4 kB view details)

Uploaded Source

Built Distribution

pylogg-0.2.0-py3-none-any.whl (14.6 kB view details)

Uploaded Python 3

File details

Details for the file pylogg-0.2.0.tar.gz.

File metadata

  • Download URL: pylogg-0.2.0.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

Hashes for pylogg-0.2.0.tar.gz
Algorithm Hash digest
SHA256 f0769807b08dd9f1b02a2a77f7fccbed8395514c4458973c885d2e43b57ae324
MD5 ef4e4dcf01d9709b41710c3ca56cb251
BLAKE2b-256 ede9b3b707ca4b9fb248de8a7e435420e7d4b7cc2cd766a6be809789cd4817f7

See more details on using hashes here.

File details

Details for the file pylogg-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: pylogg-0.2.0-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

Hashes for pylogg-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f13ee78dea39ca525a4e33514e1a0205fc9608bf798dda18097c6a3d67892c6d
MD5 03ead1033921f5b8b72cbd7c152e6162
BLAKE2b-256 eb1ee648e22b21e1f3292dd9d4de57887c3fde2ff16f32f7d372d5157f59b27e

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page