Skip to main content

Shared utilities for logging and configuration management

Project description

Spello Consulting Utility Library

A Python utility library for log file management and YAML configuration file management

Details to follow

Example code

import sys

from config_schemas import ConfigSchema
from sc_utility import SCConfigManager, SCLogger

CONFIG_FILE = "config.yaml"


def main():
    print("Hello from sc-utility!")

    # Get our default schema, validation schema, and placeholders
    schemas = ConfigSchema()

    # Initialize the SC_ConfigManager class
    try:
        config = SCConfigManager(
            config_file=CONFIG_FILE,
            default_config=schemas.default,  # Replace with your default config if needed
            validation_schema=schemas.validation,  # Replace with your validation schema if needed
            placeholders=schemas.placeholders  # Replace with your placeholders if needed
        )
    except RuntimeError as e:
        print(f"Configuration file error: {e}", file=sys.stderr)
        return

    config_value = config.get("AmberAPI", "APIKey", default="this is the default value")
    if config_value is None:
        print("Configuration value not found")
    else:
        print(f"Configuration loaded successfully. Sample value: {config_value}")

    # Initialize the SC_Logger class
    try:
        logger = SCLogger(config.get_logger_settings())
    except RuntimeError as e:
        print(f"Logger initialisation error: {e}", file=sys.stderr)
        return

    logger.log_message("This is a test message at the debug level.", "debug")
    # logger.log_message("This is a test message at the error level.", "error")

    # Setup email
    email_settings = config.get_email_settings()
    logger.register_email_settings(email_settings)

    if logger.send_email("Hello world", "This is a test email from the sc-utility test harness."):
        logger.log_message("Email sent OK.", "detailed")

    if logger.get_fatal_error():
        print("Prior fatal error detected.")
        logger.clear_fatal_error()

    # logger.log_fatal_error("This is a test fatal error message.")

    logger.clear_fatal_error()

if __name__ == "__main__":
    main()

Exceptions

The initialisation functions throw RuntimeError exceptions if a fatal error is encountered.

Project details


Release history Release notifications | RSS feed

This version

1.1.3

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sc_utility-1.1.3.tar.gz (9.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sc_utility-1.1.3-py3-none-any.whl (10.6 kB view details)

Uploaded Python 3

File details

Details for the file sc_utility-1.1.3.tar.gz.

File metadata

  • Download URL: sc_utility-1.1.3.tar.gz
  • Upload date:
  • Size: 9.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for sc_utility-1.1.3.tar.gz
Algorithm Hash digest
SHA256 f0c0bad5631a2b26eaaa84ab3a1a583a6d1bf9f1b241c11eefd31925d2ab14d6
MD5 23555595879c332cd858ba42b8912135
BLAKE2b-256 6f23d755c1c8a7f6f9e6fcf9d0ff7ffc4ea5e3397dfcb05f43f79a9459b5e7f0

See more details on using hashes here.

Provenance

The following attestation bundles were made for sc_utility-1.1.3.tar.gz:

Publisher: publish.yml on NickElseySpelloC/sc_utility

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file sc_utility-1.1.3-py3-none-any.whl.

File metadata

  • Download URL: sc_utility-1.1.3-py3-none-any.whl
  • Upload date:
  • Size: 10.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for sc_utility-1.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 d0f43aa390f6176716e07fa28eed3f69cacc8af65df5dcd10ceba9ced8654e23
MD5 be4777b76e5d4280c912326e91cbe19d
BLAKE2b-256 7722c606b710cb571f37a3d37067f44c02d5f9ade64ca5bf530910f388ec4109

See more details on using hashes here.

Provenance

The following attestation bundles were made for sc_utility-1.1.3-py3-none-any.whl:

Publisher: publish.yml on NickElseySpelloC/sc_utility

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page