Skip to main content

pyfortified-logging

This Python project is an extension of the native Python component logging providing more robust message formatting for standard and JSON logging output, and in addtion allowing for extra content populated as dictionaries.

pypi.org

https://pypi.org/project/pyfortified-logging/

Work In Progress

The following still needs to be performed for this Python project:

  • Unit-testing: This project will be switching over to using Python native Unit testing framework unittest.

  • More concise documentation is required.

  • Travis CI

  • Badges

Badges

Install

pip install pyfortified_logging

Architecture

Function: get_logger()

def get_logger(
    logger_name,
    logger_version=None,
    logger_level=logging.INFO,
    logger_format=LoggingFormat.JSON,
    logger_output=LoggingOutput.STDOUT_COLOR,
    logger_handler=None
):

get_logger(): Parameters

Parameter

Purpose

logger_name

Return a logger with the specified name or, if name is None, return a logger which is the root logger of the hierarchy.

logger_version

logger_format

LoggingFormat

logger_output

LoggingOutput

logger_handler

logging.StreamHandler() or logging.FileHandler()

Logging Levels

Same Python logging levels, including one additional level NOTE.

Level

Purpose

DEBUG

Detailed information, typically of interest only when diagnosing problems.

NOTE

Detailed information, request processing, for example, request using cURL.

INFO

Confirmation that things are working as expected. [DEFAULT]

WARNING

An indication that something unexpected happened, or indicative of some problem in the near future. The software is still working as expected.

ERROR

Due to a more serious problem, the software has not been able to perform some function.

CRITICAL

A serious error, indicating that the program itself may be unable to continue running.

Logging Format

Format

Purpose

STANDARD

Standard logging format.

JSON

JSON logging format. [DEFAULT]

class LoggingFormat(object):
    """TUNE Logging Format ENUM
    """
    STANDARD = "standard"
    JSON = "json"

Logging Output

Output

Purpose

STDOUT

Standard Output to terminal

STDOUT_COLOR

Standard Output using colored terminal

FILE

Standard Output to file created within ./tmp/log_<epoch time seconds>.json.

class LoggingOutput(object):
    """Logging Format ENUM
    """
    STDOUT = "stdout"
    STDOUT_COLOR = "color"
    FILE = "file"

Logging JSON Format

import logging
from pyfortified_logging import (LoggingFormat, get_logger, __version__)

log = get_logger(
    logger_name=__name__,
    logger_version=__version__,
    logger_format=LoggingFormat.JSON,
    logger_level=logging.NOTE
)

log.info("logging: info", extra={'test': __name__})
log.note("logging: note", extra={'test': __name__})
log.debug("logging: debug", extra={'test': __name__})
log.warning("logging: warning", extra={'test': __name__})
log.error("logging: error", extra={'test': __name__})
log.critical("logging: critical", extra={'test': __name__})
log.exception("logging: exception", extra={'test': __name__})

Logging JSON Example Output

$ python3 examples/example_logging_json.py

{"asctime": "2018-05-11 05:41:39 -0700", "levelname": "INFO", "name": "__main__",
"version": "0.1.6", "message": "logging: info", "test": "__main__"}
{"asctime": "2018-05-11 05:41:39 -0700", "levelname": "NOTE", "name": "__main__",
"version": "0.1.6", "message": "logging: note", "test": "__main__"}
{"asctime": "2018-05-11 05:41:39 -0700", "levelname": "WARNING", "name": "__main__",
"version": "0.1.6", "message": "logging: warning", "test": "__main__"}
{"asctime": "2018-05-11 05:41:39 -0700", "levelname": "ERROR", "name": "__main__",
"version": "0.1.6", "message": "logging: error", "test": "__main__"}
{"asctime": "2018-05-11 05:41:39 -0700", "levelname": "CRITICAL", "name": "__main__",
"version": "0.1.6", "message": "logging: critical", "test": "__main__"}
{"asctime": "2018-05-11 05:41:39 -0700", "levelname": "ERROR", "name": "__main__",
"version": "0.1.6", "message": "logging: exception", "exc_info": "NoneType: None",
"test": "__main__"}

Requirements

pyfortified-logging module is built upon Python 3 and has dependencies upon several Python modules available within Python Package Index PyPI.

make install-requirements

or

python3 -m pip uninstall --yes --no-input -r requirements.txt
python3 -m pip install --upgrade -r requirements.txt

Dependencies

Metadata

Release files for pyfortified-logging 0.2.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pyfortified-logging 0.2.1
File Size Uploaded Provenance Actions
pyfortified-logging-0.2.1.tar.gz 31.3 kB Without provenance Details for pyfortified-logging-0.2.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pyfortified-logging 0.2.1
File Interpreter ABI Platform Actions
pyfortified_logging-0.2.1-py3-none-any.whl Python 3 none any Details for pyfortified_logging-0.2.1-py3-none-any.whl

Total release size: 43.8 kB

Release files / pyfortified-logging-0.2.1.tar.gz

Download URL pyfortified-logging-0.2.1.tar.gz
Size 31.3 kB
Tags Source
SHA-256 checksum
How to use checksums
3399366edc29982311de270a8f020dd395b7f59a243cfe246b13ef67c96955ce
BLAKE2b-256 checksum
How to use checksums
43af51b1347af203ee9f2eafd762472e7736274a3507c2f0141ae29dd33ef3a3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via Python-urllib/3.6

Release files / pyfortified_logging-0.2.1-py3-none-any.whl

Download URL pyfortified_logging-0.2.1-py3-none-any.whl
Size 12.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8acacafb289bcc53fd29f45167ac9a63f56b674e87711d3679ec928876778416
BLAKE2b-256 checksum
How to use checksums
77a19ceb091ef182520590d75658a9f6e55879047f1eb6f29ef5bc69a7b00ec5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via Python-urllib/3.6

Security for pyfortified-logging 0.2.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page