Skip to main content

loggpy

A powerful and flexible Python logging library that extends the standard logging module with custom log levels and colored output support.

Features

  • Custom log levels (NOTICE, SPAM, SUCCESS, VERBOSE, LOGKEY)
  • Colored output support using coloredlogs
  • Blacklist functionality to suppress specific loggers
  • Customizable color schemes and formats
  • File and console logging support

Installation

pip install loggpy

Basic Usage

from loggpy import Logger
import logging

# Basic setup with console output
Logger.mount(level=logging.INFO)
log = Logger(__name__)

# Use standard log levels
log.debug("Debug message")
log.info("Info message")
log.warning("Warning message")
log.error("Error message")

# Use custom log levels
log.notice("Notice message")
log.spam("Spam message")
log.success("Success message")
log.verbose("Verbose message")
log.logkey("API Key: xyz123")  # For logging sensitive or key information

Advanced Configuration

Logging to File

from pathlib import Path
from datetime import datetime

# Log to both console and file
Logger.mount(
    level=logging.DEBUG,
    HandlerFilename=Path("logs/app.log"),
)

Dynamic Log File Names

Logger.mount(
    level=logging.INFO,
    HandlerFilename=Path(
        f"logs/app_{datetime.now().strftime('%Y-%m-%d_%H_%M_%S')}.log"
    )
)

Blacklisting Loggers

# Suppress logs from specific modules
Logger.mount(
    level=logging.INFO,
    blacklist=[
        "filelock",
        "oauthlib",
        "google",
        "charset_normalizer"
    ]
)

Custom Color Schemes

Logger.mount(
    level=logging.INFO,
    field_styles={
        "asctime": {"color": 35},
        "name": {"color": 197},
        "levelname": {"color": 244, "bold": True},
    },
    level_styles={
        "spam": {"color": "green", "faint": True},
        "debug": {"color": 69},
        "verbose": {"color": "blue"},
        "info": {},
        "notice": {"color": "magenta"},
        "warning": {"color": "yellow"},
        "success": {"color": 67, "bold": True},
        "error": {"color": "red"},
        "critical": {"color": "red", "bold": True},
    }
)

Log Levels

Level Value Description
SPAM 5 Even more detailed than DEBUG
VERBOSE 15 Between DEBUG and INFO
LOGKEY 21 Important key information or sensitive data
NOTICE 25 Normal but significant events
SUCCESS 35 Successful operations

Full Example

from loggpy import Logger
import logging
from pathlib import Path

def setup_logging(debug_mode=False):
    # Configure logging with custom settings
    Logger.mount(
        level=logging.DEBUG if debug_mode else logging.INFO,
        HandlerFilename=Path("logs/app.log"),
        blacklist=["filelock", "oauthlib"],
        field_styles={
            "asctime": {"color": 35},
            "name": {"color": 197},
            "levelname": {"color": 244, "bold": True},
        },
        level_styles={
            "spam": {"color": "green", "faint": True},
            "debug": {"color": 69},
            "verbose": {"color": "blue"},
            "success": {"color": 67, "bold": True},
        }
    )

    return Logger(__name__)

# Initialize logger
log = setup_logging(debug_mode=True)

# Example usage
log.spam("Starting application initialization...")
log.debug("Loading configuration...")
log.verbose("Configuration loaded successfully")
log.info("Application started")
log.notice("New user connected")
log.logkey("Session token: 8f7d56a2-bc4d-4c12-a891-45e70542b21f")
log.success("Transaction completed successfully")
log.warning("High memory usage detected")
log.error("Failed to connect to database")
log.critical("System shutdown initiated")

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Acknowledgments

  • Built on top of Python's standard logging module
  • Uses coloredlogs for terminal color support

Metadata

Release files for loggpy 0.1.0

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

Built distribution (wheel)

Table of built distributions (wheels) for loggpy 0.1.0
File Interpreter ABI Platform Actions
loggpy-0.1.0-py3-none-any.whl Python 3 none any Details for loggpy-0.1.0-py3-none-any.whl

Release files / loggpy-0.1.0-py3-none-any.whl

Download URL loggpy-0.1.0-py3-none-any.whl
Size 6.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b52bc80470d1e3e5949286c2514f8ae4279e721015cb41295ed2c4e82f17a443
BLAKE2b-256 checksum
How to use checksums
9f5cc0ee7c6f0cdb0f429db39b772b0a08c476cb9fa049969f594405693fd0d9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.10.0

Security for loggpy 0.1.0

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.

Release history Release notifications | RSS feed

This release

0.1.0 This release

1 release file No provenance

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