Skip to main content

A simple global logging wrapper library

Project description

Simple Global Logging

A simple Python logging extension library that enhances the standard logging functionality with global configuration and stdout capture capabilities.

Features

  • Global Logging Setup: Initialize once, use everywhere with standard import logging
  • Automatic File Output: Logs saved to timestamped files in out/ directory
  • Custom Filename Support: Optional custom filenames with automatic append mode
  • Standard Output Capture: Capture console output to log files
  • pytest Integration: Capture pytest output via conftest.py
  • Configurable Timezone: All timestamps in specified timezone (default: UTC)

[!IMPORTANT] This library clears all existing handlers from the root logger and its children during initialization. If your application uses other logging handlers, make sure to:

  • Initialize this library before setting up other handlers
  • Or manually re-add your handlers after initialization

Installation

pip install simple-global-logging

Quick Start

import simple_global_logging
import logging

# Basic setup
simple_global_logging.setup_logging(verbose=True)
logging.info("This will be logged to file and console")

# With stdout capture
simple_global_logging.setup_logging_with_stdout_capture()
print("This will also be logged")

API Reference

Core Functions

# Basic logging setup
setup_logging(
    verbose=False,     # Enable DEBUG level if True
    base_dir="out",    # Log directory
    tz=None,          # Timezone (default: UTC)
    filename=None     # Optional custom filename (default: auto-generated)
)

# With stdout capture
setup_logging_with_stdout_capture(
    verbose=False,
    base_dir="out",
    remove_ansi=True,  # Remove terminal color codes
    tz=None,
    filename=None     # Optional custom filename (default: auto-generated)
)

# Utility functions
get_logger(name)           # Get logger instance
restore_stdout()           # Restore original stdout
get_current_log_file()     # Get current log file path
get_current_timezone()     # Get current timezone

Log File Format

  • Location: out/ directory (customizable)
  • Filename:
    • Default: YYYYMMDD-0000001.log (7-digit sequential number)
    • Custom: Use specified filename with append mode
  • Content: Timestamps in specified timezone

Examples

The library includes example scripts in the examples/ directory:

  • basic_usage.py: Basic logging setup
  • stdout_capture_example.py: Output capture
  • submodule.py: Logging from different modules
  • timezone_example.py: Timezone configuration
  • custom_filename_example.py: Custom filename and append mode

For pytest integration, see conftest_template.py in the tests/ directory.

Requirements

  • Python 3.10 or higher

Development

This library was developed using Cursor, a modern AI-powered IDE.

License

Apache License 2.0

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

simple_global_logging-0.1.2.tar.gz (15.0 kB view details)

Uploaded Source

Built Distribution

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

simple_global_logging-0.1.2-py3-none-any.whl (11.6 kB view details)

Uploaded Python 3

File details

Details for the file simple_global_logging-0.1.2.tar.gz.

File metadata

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

File hashes

Hashes for simple_global_logging-0.1.2.tar.gz
Algorithm Hash digest
SHA256 704a1694f80cbd74f5c321d72976ee36fbd9acf7fd64da06a6bf08c8f203cd4b
MD5 4d377195e556493b2a0c17be678ec217
BLAKE2b-256 351c52b843216ab88317830660b710b76601de33aee746ba7ccaa2f1b075e0db

See more details on using hashes here.

Provenance

The following attestation bundles were made for simple_global_logging-0.1.2.tar.gz:

Publisher: publish-pypi.yml on hasegama/simple-global-logging

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

File details

Details for the file simple_global_logging-0.1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for simple_global_logging-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 1c9701c4afd64493902b881ae382c014907d9db9dc63401c91f71abc3eef8b4a
MD5 4662423f6a5f34b24f1e6c3c3ff1644e
BLAKE2b-256 fda68b5a442f6fbcd19ddc1707fad8496d479f573cc010c20afc63ef46a58722

See more details on using hashes here.

Provenance

The following attestation bundles were made for simple_global_logging-0.1.2-py3-none-any.whl:

Publisher: publish-pypi.yml on hasegama/simple-global-logging

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