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
  • 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)
)

# With stdout capture
setup_logging_with_stdout_capture(
    verbose=False,
    base_dir="out",
    remove_ansi=True,  # Remove terminal color codes
    tz=None
)

# 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: YYYYMMDD-0000001.log (7-digit sequential number)
  • 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

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.1.tar.gz (13.6 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.1-py3-none-any.whl (11.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: simple_global_logging-0.1.1.tar.gz
  • Upload date:
  • Size: 13.6 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.1.tar.gz
Algorithm Hash digest
SHA256 3a3b0441dd4ee8a37b9f1e97e4513d1f0ba06bb3baad8557f5b8059501f73388
MD5 21eb5aed2ab2db56e0a7b68a86ce6b3d
BLAKE2b-256 845cf176c988513f376ff3976657c6b0ee86b97865d7cd01037f65670b2d51f3

See more details on using hashes here.

Provenance

The following attestation bundles were made for simple_global_logging-0.1.1.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.1-py3-none-any.whl.

File metadata

File hashes

Hashes for simple_global_logging-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f7364a102f3a5a80bae8d7db5403981d2720ab8d988dc46ac52902fa77180397
MD5 f65521bfe626ad02d8be600563600660
BLAKE2b-256 53d952d730f17069a2550e6c18dcabead9e40f2f0fba33a47c0f2cd8449c3ec8

See more details on using hashes here.

Provenance

The following attestation bundles were made for simple_global_logging-0.1.1-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