Skip to content

Latest commit

 

History

41 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

spiffy dog Loggy

Personal Python logging and utilities library. Feel free to use it or don't, this saves me time copy-pasting the same code between projects. There are many like it, but this one is mine.

Features

  • INFO, DEBUG, or automatic silent mode
  • tqdm loading bar support for async, threaded, or manual increments
  • Record objects for storing logs
  • Misc. util objects like timers

Installation

pip install git+https://github.com/dlg1206/loggy.git

or add to requirements.txt

loggy @ git+https://github.com/dlg1206/loggy.git

Basic Usage

INFO mode

import loggy

loggy.info("Hello")
loggy.warn("Hello")
loggy.error("Hello")

terminal output of info mode

DEBUG mode

import loggy
from loggy import Level

loggy.set_log_level(Level.DEBUG)

loggy.debug_info("Hello")
loggy.debug_warn("Hello")
loggy.debug_error("Hello")
loggy.info("Hello")
loggy.warn("Hello")
loggy.error("Hello")

terminal output of debug mode

SILENT mode

All loggy output is silenced

import loggy

loggy.set_log_level(None)

print("foo")
loggy.debug_info("Hello")
loggy.debug_warn("Hello")
loggy.debug_error("Hello")
loggy.info("Hello")
loggy.warn("Hello")
loggy.error("Hello")
print("bar")

terminal output of silent mode

Fatal

Program immediately exits with a non-zero code

import loggy

print("foo")
loggy.fatal("goodbye")
print("bar")

terminal output of fatal

Async / Threaded / Manual Loading Bars

Concept is the same with async, just replace futures with coroutines

INFO Mode

import time
from concurrent.futures import ThreadPoolExecutor

import loggy


def sleep() -> str:
    time.sleep(1)
    return "Awake!"


with ThreadPoolExecutor() as exe:
    futures = [exe.submit(sleep) for _ in range(3)]

    for f in loggy.threaded_data_queue(futures, description="sleeping", unit="zzz"):
        result = f.result()
        # do extra processing here
        loggy.debug_info(result)

loggy.info("Done!")

terminal info loading bar

DEBUG Mode

import time
from concurrent.futures import ThreadPoolExecutor

import loggy
from loggy import Level

loggy.set_log_level(Level.DEBUG)  # <-- Set mode to debug


def sleep() -> str:
    time.sleep(1)
    return "Awake!"


with ThreadPoolExecutor() as exe:
    futures = [exe.submit(sleep) for _ in range(3)]

    for f in loggy.threaded_data_queue(futures, description="sleeping", unit="zzz"):
        result = f.result()
        # do extra processing here
        loggy.debug_info(result)

loggy.info("Done!")

terminal debug loading bar

Additional Details

Include additional details not embedded in the message, included by default. Supported by all methods

import loggy

loggy.info("Hello", foo=True, bar="bazz")

# Disable additional details
loggy.info("Hello", emit_details=False, foo=True, bar="bazz")

logging with and without details

Exceptions

Include exceptions in the details. Supported by warn, error, and fatal methods

import loggy

try:
    raise RuntimeError("foobar")
except RuntimeError as e:
    loggy.error(e)

log when passing exception

About

Personal logging and utils library

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Used by

Contributors

Languages