Skip to main content

A logging component with colored output and automated file organization.

Project description

🐾 ColorPaws

A powerful, flexible logging component that enhances Python's built-in logging with colored output and automated file organization. Perfect for both console applications and services requiring detailed logging.

🌟 Key Features

  • 🎨 Colored console output with intuitive level-based colors
  • 🖥️ Cross-platform support (Windows and Unix-like systems)
  • 📁 Automatic date-based log file organization
  • 🔄 Smart handler management (no duplicates)
  • ⚙️ Configurable dual-output (console and/or file)
  • 🕒 Timestamp-based log file naming

🎨 Color Scheme

Log Level Color Use Case
DEBUG Blue Detailed information for debugging
INFO Green General operational messages
WARNING Yellow Warning messages for potential issues
ERROR Red Error messages for serious problems
CRITICAL Magenta Critical failures requiring immediate attention

📘 Usage Examples

Basic Console Logging

from colorpaws import setup_logger

# Initialize with console output only
logger = setup_logger(
    name="MyApp",
    log_on=True
)

# Example usage
logger.info("Application started")
logger.debug("Configuration loaded successfully")
logger.warning("Resource usage above 80%")

Advanced File and Console Logging

from colorpaws import setup_logger

# Initialize with both console and file logging
logger = setup_logger(
name="MyApp",
log_on=True,
log_to="logs"
)

# Comprehensive logging example
try:
    # Your code here
    logger.info("Processing started")
    logger.debug("Loading configuration...")

    # Simulate an error condition
    raise ValueError("Invalid input detected")

except Exception as e:
    logger.error(f"Process failed: {str(e)}")
    logger.debug("Stack trace:", exc_info=True)

📁 Log File Organization

The component automatically organizes log files by date:

logs/
├── 2024-01-01/
│   ├── 20240101_12000000_MyApp.log
│   ├── 20240101_12000001_MyApp.log
│   └── ...

⚙️ Configuration

setup_logger() Parameters

Parameter Type Default Description
name str Required Logger instance name
log_on bool False Enable/disable logging
log_to str None Log file directory path

🛠️ Installation

pip install colorpaws

🔍 Advanced Features

Handler Management

  • Automatic prevention of duplicate handlers
  • Smart console color detection
  • Windows-specific color handling via colorama

Log File Naming

  • Timestamp-based unique file names
  • Date-based directory structure
  • Append mode for continuous logging

Format Customization

Default format: YYYY-MM-DD HH:MM:SS - LEVEL - Message

💡 Best Practices

  1. Logger Naming

    # Use meaningful, hierarchical names
    logger = setup_logger("MyApp.SubModule")
    
  2. Log Level Usage

    logger.debug("Detailed debugging information")
    logger.info("General operational messages")
    logger.warning("Warning messages")
    logger.error("Error messages")
    logger.critical("Critical failures")
    
  3. Exception Handling

    try:
        # Your code
    except Exception as e:
        logger.error("Operation failed", exc_info=True)
    

⚠️ Important Notes

  • Log files are created with unique timestamps to prevent overwrites
  • Console colors automatically adjust based on terminal capabilities
  • Windows color support is handled transparently
  • Logger instances are singleton per name
  • All timestamps use local system time

🤝 Contributing

Feel free to submit issues and enhancement requests!

📄 License

This component is available under the MIT License.

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

colorpaws-1.0.0.tar.gz (4.8 kB view details)

Uploaded Source

Built Distribution

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

colorpaws-1.0.0-py3-none-any.whl (5.0 kB view details)

Uploaded Python 3

File details

Details for the file colorpaws-1.0.0.tar.gz.

File metadata

  • Download URL: colorpaws-1.0.0.tar.gz
  • Upload date:
  • Size: 4.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.10.11

File hashes

Hashes for colorpaws-1.0.0.tar.gz
Algorithm Hash digest
SHA256 42965bef322b46f821836fc83061270f63e0affa7c66f3a62b6978060f461cd2
MD5 1a0b736218ba3da765cb356712d14dda
BLAKE2b-256 3d981398aa50d0f94c87f7d4eaa1b3daf12369284a61f7a4f70dc69f6a6ba5a3

See more details on using hashes here.

File details

Details for the file colorpaws-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: colorpaws-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 5.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.10.11

File hashes

Hashes for colorpaws-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ab23d34cda19beede603dab22c62584dad960c3f7d4be1d43682d1c7f025eae6
MD5 dcf2ab06639aa7f142c325b52dac94f5
BLAKE2b-256 add4234170d774156b1c06fb3e2300517f09d55b52a51cda84866e8ddcb55780

See more details on using hashes here.

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