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

Uploaded Source

Built Distribution

File details

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

File metadata

File hashes

Hashes for crashvb_logging_utilities-0.1.1.tar.gz
Algorithm Hash digest
SHA256 8fe4694229ea451c179df6e6194b20d84ff4a44c3f100914188f303d1aa12ec4
MD5 5def40d684141433e91e9ab0e88d6697
BLAKE2b-256 d910749cd4cfe12fa4bd9cb6b969f5e09eb8403dfc0da1da8d5f57273d595b00

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for crashvb_logging_utilities-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 3493096c5fe1916c0c1ce31d27ebaee27ac3d052e832d9a9da7f977321586be8
MD5 b54b8a6562f67d68f675eafb95995b38
BLAKE2b-256 b187decc2289163142b68d6ca04e00f931bc7ea87a40742fa2904d223bd5815f

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