Skip to main content

A collection of logging utilities

Project description

https://img.shields.io/pypi/v/alogging.svg https://img.shields.io/travis/alikins/alogging.svg Documentation Status Updates Python package github action

Python logging tools and utils.

Usage

To use alogging in a project:

import alogging

Examples

Basic use of alogging:

import alogging

# create a logging.Logger object, will use the __name__ of the
# module by default. Equilivent to 'log = logging.getLogger(__name__)'
log = alogging.get_logger()

log.debug('created a Logger object so use it for a debug msg')

if __name__ = '__main__':
    main_log = alogging.app_setup(name='example.main')
    main_log.debug('started main')

More advanced:

import alogging

# local alias for alogging.a()
a = alogging.a

log = alogging.get_logger()

class ThingToDo(object):
    def __init__(self, requirement, priority=None, assigner=None):
        # get a Logger named 'example.ThingToDo'
        self.log = alogging.get_class_logger(self)

        self.log.info('Task as assigned: req=%s, pri=%s, ass=%s', requirement, priority, assigner)

        priority = priority or 'never'

        self.log.info('Task reprioritized: req=%s, pri=%s, ass=%s', requirement, priority, assigner')


# alogging.t decorator will log when the decorated method is called,
# what args it was passed, and what it's return value was

@alogging.t
def space_out_for_while(duration=None):
    # space out for 10 minutes by default
    duration = duration or 600

    # return the total amount of work accomplished
    return 0

def find_coffee(coffee_places):
    log.debug('looking for coffee')
    return None

def do_startup_stuff():
    coffee_places = ['piehole', 'mug_on_desk', 'coffee_machine', 'krankies']
    # log the the args to find_coffee as it is called
    has_coffee = a(find_coffee(coffee_places))

    work_accomplished = space_out_for_while(duration=300)

def do_work():
    next_task = TaskToDo('finish TODO list', assigner='Lumberg')
    if not next_task:
        return

    # oh no, work...
    log.error("I'm slammed at the moment, I can't do %s', next_task)
    raise Exception()

if __name__ = '__main__':
    # use some reasonable defaults for setting up logging.
    # - log to stderr
    # - use a default format:
    #   """%(asctime)s,%(msecs)03d %(levelname)-0.1s %(name)s %(processName)s:%(process)d %(funcName)s:%(lineno)d - %(message)s"""
    main_log = alogging.app_setup(name='example.main')
    main_log.debug('Log to logging "example.main"')

    do_startup_stuff()

    try:
        do_work()
    except Exception as exc:
        # gruntle a bit and continue
        log.exception(exc)

    return 0

License

  • Free software: MIT license

Features

  • TODO

Authors

  • Adrian Likins

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

alogging-0.6.2.tar.gz (14.7 kB view details)

Uploaded Source

Built Distribution

alogging-0.6.2-py2.py3-none-any.whl (17.1 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file alogging-0.6.2.tar.gz.

File metadata

  • Download URL: alogging-0.6.2.tar.gz
  • Upload date:
  • Size: 14.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.5

File hashes

Hashes for alogging-0.6.2.tar.gz
Algorithm Hash digest
SHA256 f4093963001f4d8f3a405d0b92c919d0ad518920a7001cf88129603d45693115
MD5 1c3eb68cf556a34f695cc31354ffe7aa
BLAKE2b-256 04f1a19ce1ce9dc8b4fa6375139fa9551e03905c8efce898a32817b0fa614775

See more details on using hashes here.

File details

Details for the file alogging-0.6.2-py2.py3-none-any.whl.

File metadata

  • Download URL: alogging-0.6.2-py2.py3-none-any.whl
  • Upload date:
  • Size: 17.1 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.5

File hashes

Hashes for alogging-0.6.2-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 8be304d56135a4a55fcc49710ab6d727de0403572c62d0395f64caaff04cd788
MD5 829b9727ff31fc9a333780579f1b128b
BLAKE2b-256 721518c62fc62aa6584d6bda6eb0699872225f688708cf99d7ce66c5f003f0e0

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