Skip to main content

Consolidation of logging utilities.

Project description

crashvb-logging-utilities

pypi version build status coverage status python versions linting code style license

Overview

Consolidation of logging utilities.

Installation

From pypi.org

$ pip install crashvb-logging-utilities

From source code

$ git clone https://github.com/server27nw/crashvb-logging-utilities
$ cd crashvb-logging-utilities
$ virtualenv env
$ source env/bin/activate
$ python -m pip install --editable .[dev]

Usage

import click
import logging
import sys
from traceback import print_exception
from typing import NamedTuple

from click.core import Context
from crashvb_logging_utilities import LOGGING_DEFAULT, logging_options, set_log_levels

LOGGER = logging.getLogger(__name__)

class TypingContextObject(NamedTuple):
    # pylint: disable=missing-class-docstring
    ...
    verbosity: int

@click.group()
@logging_options
@click.pass_context
def cli(
    context: Context,
    verbosity: int = LOGGING_DEFAULT,
):
    """Main group."""

    if verbosity is None:
        verbosity = LOGGING_DEFAULT

    set_log_levels(verbosity)

    context.obj = TypingContextObject(
        # ...
        verbosity=verbosity,
    )

@cli.command(name="command1", ...)
@click.option( ... )
@click.pass_context
def command1(context: Context, ...):
    """Command #1"""
    ctx = context.obj
    try:
	    ...
    except Exception as exception:  # pylint: disable=broad-except
        if ctx.verbosity > 0:
            logging.fatal(exception)
        if ctx.verbosity > LOGGING_DEFAULT:
            exc_info = sys.exc_info()
            print_exception(*exc_info)
        sys.exit(1)
    

Environment Variables

Variable Default Value Description

Development

Source Control

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

crashvb_logging_utilities-0.1.0.tar.gz (8.1 kB view details)

Uploaded Source

Built Distribution

File details

Details for the file crashvb_logging_utilities-0.1.0.tar.gz.

File metadata

File hashes

Hashes for crashvb_logging_utilities-0.1.0.tar.gz
Algorithm Hash digest
SHA256 ddb441739a558f5b85f4cf2ff7ea66b2b3845ee7225a35277e9a58bdb0e988a4
MD5 29b15fc766368ca4444dddff61e9ae37
BLAKE2b-256 56439f1f0ad037a1081e763ff9e06833f6779950c4dc0382e1562439ad1c4c64

See more details on using hashes here.

File details

Details for the file crashvb_logging_utilities-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for crashvb_logging_utilities-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 92e38742a729c82c11f9e2a5f679646ef5b841a40575437a51240cf2aeb9e75e
MD5 a8541b76bbb5742256a6023c7882ba7d
BLAKE2b-256 67b5fc90154a1b045e998359e40a6f3c365692dd08c94b12a5123b9857e038fb

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