Skip to main content

A simple, beautiful logger with a clean and intuitive interface

Project description

Loggity

A simple, beautiful logger with a clean and intuitive interface

Version Status License Python

Features

  • Colorful output: Beautiful ANSI colors for different log levels
  • Flexible timestamps: Custom timestamp formats using strftime
  • Simple API: Just create a logger and start logging
  • Multiple log levels: INFO (blue), WARN (yellow), ERROR (red), DEBUG (white), SUCCESS (green)
  • Custom headers: Create your own log types with custom colors
  • Lightweight: Pure Python, no external dependencies
  • Clean formatting: Consistent spacing and aligned output
  • Dataclass config: Type-safe configuration with LoggerConfig
  • Runtime formatting: Change timestamp format on the fly with set_format()

Installation

pip install loggity

Quick Start

from loggity import Logger

# Create a logger instance with default settings
log = Logger()

# Start logging with beautiful colors
log.info("Application started")              # Blue
log.success("Database connected successfully") # Green
log.warn("Disk space running low")           # Yellow
log.error("Failed to send email")             # Red
log.debug("Cache miss for key: user_123")     # White

Configuration

Loggity uses a dataclass-based configuration system for type-safe and flexible setup:

LoggerConfig Parameters

Parameter Type Default Description
colored bool True Enable/disable ANSI colors
timestamps bool False Enable/disable timestamps
timeformat str or None None strftime format string (requires timestamps=True)

Basic Configuration

from loggity import Logger, LoggerConfig

# Create configuration
config = LoggerConfig(
    colored=True,
    timestamps=True,
    timeformat="%H:%M:%S"  # 24-hour format: 14:30:22
)

# Apply configuration
log = Logger(config=config)

log.info("Server started")
# [14:30:22] INFO:    Server started

Timestamp Formats

The timeformat parameter accepts any valid strftime format string:

# Various timestamp formats
formats = {
    "simple": "%H%M%S",           # 143022
    "readable": "%H:%M:%S",        # 14:30:22
    "with_ms": "%H:%M:%S.%f",      # 14:30:22.123456
    "date_and_time": "%Y-%m-%d %H:%M:%S",  # 2024-01-15 14:30:22
    "compact": "%y%m%d_%H%M%S",    # 240115_143022
}

for name, fmt in formats.items():
    config = LoggerConfig(timestamps=True, timeformat=fmt)
    log = Logger(config=config)
    log.info(f"Testing {name} format")

Runtime Format Changes

Change the timestamp format dynamically using set_format():

log = Logger(config=LoggerConfig(timestamps=True, timeformat="%H:%M:%S"))

log.info("Starting process")        # [14:30:22] INFO:    Starting process

# Switch to compact format
log.set_format("%H%M%S")
log.info("Processing data")          # [143022] INFO:    Processing data

# Disable timestamps
log.set_format("")                   # Empty string disables timestamps
log.info("Task completed")           # INFO:    Task completed

API Reference

Logger Methods

Basic Methods

All basic methods come with predefined colors:

Method Color Description
info(message) Blue Informational messages
warn(message) Yellow Warning messages
error(message) Red Error messages
debug(message) White Debug messages
success(message) Green Success messages

Configuration Methods

Method Description Example
set_format(format_string) Change timestamp format at runtime log.set_format("%H:%M:%S")

Custom Logging

Create logs with custom headers and colors:

from loggity import Logger, Colors, LoggerConfig

log = Logger(config=LoggerConfig(timestamps=True, timeformat="%H:%M:%S"))

# Custom log types with any color
log.custom("AUDIT", Colors.MAGENTA, "User admin performed deletion")
log.custom("METRIC", Colors.CYAN, "Response time: 245ms")
log.custom("SECURITY", Colors.RED, "Failed login attempt from 192.168.1.100")

Available Colors

The Colors class provides ANSI color codes:

Color Usage
Colors.BLACK log.custom("BLACK", Colors.BLACK, "message")
Colors.RED log.custom("RED", Colors.RED, "message")
Colors.GREEN log.custom("GREEN", Colors.GREEN, "message")
Colors.YELLOW log.custom("YELLOW", Colors.YELLOW, "message")
Colors.BLUE log.custom("BLUE", Colors.BLUE, "message")
Colors.MAGENTA log.custom("MAGENTA", Colors.MAGENTA, "message")
Colors.CYAN log.custom("CYAN", Colors.CYAN, "message")
Colors.WHITE log.custom("WHITE", Colors.WHITE, "message")

Complete Examples

Basic Usage with Different Formats

from loggity import Logger, Colors, LoggerConfig

# Logger with milliseconds timestamp
config = LoggerConfig(
    colored=True,
    timestamps=True,
    timeformat="%H:%M:%S.%f"
)
log = Logger(config=config)

log.info("Server started on port 8000")
# [14:30:22.123456] INFO:    Server started on port 8000

log.warn("Config file not found, using defaults")
# [14:30:22.123789] WARN:    Config file not found, using defaults

# Change to compact format
log.set_format("%H%M%S")
log.error("Failed to connect to database")
# [143022] ERROR:    Failed to connect to database

# Disable timestamps
log.set_format("")
log.success("Database migration completed")
# SUCCESS:    Database migration completed

Custom Headers with Colors

log.custom("METRIC", Colors.MAGENTA, "Response time: 245ms")
# [14:30:22] METRIC:    Response time: 245ms

Plain Logger (No Colors, No Timestamps)

plain_config = LoggerConfig(colored=False, timestamps=False)
plain_log = Logger(config=plain_config)

plain_log.info("Plain log entry")
# INFO:    Plain log entry

Multiple Loggers with Different Configurations

from loggity import Logger, LoggerConfig

# Development logger with detailed timestamps
dev_config = LoggerConfig(
    colored=True,
    timestamps=True,
    timeformat="%H:%M:%S.%f"
)
dev_log = Logger(config=dev_config)

# Production logger with minimal output
prod_config = LoggerConfig(colored=False, timestamps=False)
prod_log = Logger(config=prod_config)

dev_log.debug("Processing request...")
prod_log.info("Request completed")

Error Handling

The logger gracefully handles invalid timestamp formats:

log = Logger(config=LoggerConfig(timestamps=True, timeformat="%invalid"))

# Invalid format triggers a custom error log
log.info("This will still work")  
# [LOGGITY:    ERROR] Invalid format string
# INFO:    This will still work

License

This project is licensed 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

loggity-0.4.0a5.tar.gz (5.9 kB view details)

Uploaded Source

Built Distribution

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

loggity-0.4.0a5-py3-none-any.whl (6.1 kB view details)

Uploaded Python 3

File details

Details for the file loggity-0.4.0a5.tar.gz.

File metadata

  • Download URL: loggity-0.4.0a5.tar.gz
  • Upload date:
  • Size: 5.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for loggity-0.4.0a5.tar.gz
Algorithm Hash digest
SHA256 14731955d0f71993abd09c892d1b2b50f6b31f47bab45d9468fd527514f2ea58
MD5 c42f2d9579ec115795ab53160d45e2f5
BLAKE2b-256 2aff3484a5575cddd267f51738b1799f967c51e81c14c5debb4ad2f3ebd9a6ac

See more details on using hashes here.

File details

Details for the file loggity-0.4.0a5-py3-none-any.whl.

File metadata

  • Download URL: loggity-0.4.0a5-py3-none-any.whl
  • Upload date:
  • Size: 6.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for loggity-0.4.0a5-py3-none-any.whl
Algorithm Hash digest
SHA256 a68ae4f41106da2a16d0441801b5f94cc94c38c76632b479b9535ab578a9bad3
MD5 cdf59f42bfb10d55c284c680d27aea4d
BLAKE2b-256 bcb9a1359097f370837e7bd682840b0902abc173f0a575c9a4205b7e0665960d

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