Skip to main content

Personally opinionated logger in Python.

Project description

Python-PyLogg

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

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.

# Publish new tag.
./make.sh publish

About

LICENSE MIT Copyright 2023 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.1.18.tar.gz (7.3 kB view details)

Uploaded Source

Built Distribution

pylogg-0.1.18-py3-none-any.whl (7.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pylogg-0.1.18.tar.gz
  • Upload date:
  • Size: 7.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.9.18

File hashes

Hashes for pylogg-0.1.18.tar.gz
Algorithm Hash digest
SHA256 026b263d7fc2eb20be684c5ebb23b35e3bff6ee4b3901656671b5e347a0d2a49
MD5 5d8c539253f31e66bca75a8ac79ac0d6
BLAKE2b-256 7c766faa8940769f0eca562284962502a02c479d56f353e71d3a71b9fc6701bd

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pylogg-0.1.18-py3-none-any.whl
  • Upload date:
  • Size: 7.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.9.18

File hashes

Hashes for pylogg-0.1.18-py3-none-any.whl
Algorithm Hash digest
SHA256 740d07faaad7a6da787bdb94e464883516d9561296468cdf7ce47955a595190c
MD5 52085994b4a2dd4ffcaf53a25cc07848
BLAKE2b-256 c23dcd6f024b1460b5c875ef505011d876c25d2e2299febd372de11458423896

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