Skip to main content

Ultimate console logging library with gradient colors, progress bars, tables, and more

Project description

๐ŸŽจ Xylogger - Ultimate Console Logging Library

PyPI version Python 3.8+ License: MIT

Beautiful, colorful console logging with gradient colors, progress bars, tables, spinners, and more.

๐Ÿ“ฆ Installation

pip install xylogger

๐Ÿš€ Quick Start

from xylogger import console

console.info("This is an info message")
console.success("Operation completed!")
console.warning("Be careful!")
console.error("Something went wrong")
console.debug("Debug information")
console.critical("Critical failure!")

Output:

[-(12:30:45)-] [ โ— ] INFO  ยป  This is an info message
[-(12:30:45)-] [ โ— ] SUCCESS  ยป  Operation completed!
[-(12:30:45)-] [ โ— ] WARNING  ยป  Be careful!
[-(12:30:45)-] [ โ— ] ERROR  ยป  Something went wrong
[-(12:30:45)-] [ โ— ] DEBUG  ยป  Debug information
[-(12:30:45)-] [ โ— ] CRITICAL  ยป  Critical failure!

๐Ÿ“– Complete Usage Guide

1. Basic Logging

from xylogger import console, Logger

# Use the default console logger
console.info("Hello World!")
console.success("Task completed")
console.warning("Low disk space")
console.error("Connection failed")
console.debug("Variable x = 42")
console.critical("System crash!")

# Create a named logger
logger = Logger(name="MyApp")
logger.info("Custom logger message")

2. Error Logging with Exception Details

from xylogger import console

try:
    result = 1 / 0
except Exception as e:
    console.error("Division failed", error=e)

# Output:
# [-(12:30:45)-] [ โ— ] ERROR  ยป  Division failed
#             โ””โ”€โ”€> [ZeroDivisionError] division by zero

3. Section Headers (Gradient Background)

from xylogger import console

console.section("My Application")
console.section("Custom Colors", start_rgb=(255, 0, 0), end_rgb=(0, 0, 255))

4. Gradient Text

from xylogger import console

# Purple to cyan gradient
console.gradient_print("Beautiful gradient text!", (189, 147, 249), (139, 233, 253))

# Red to blue gradient
console.gradient_print("Fire to ice!", (255, 0, 0), (0, 0, 255))

# Rainbow effect
console.gradient_print("Rainbow colors!", (255, 0, 0), (0, 255, 0))

5. Dividers and Rules

from xylogger import console

console.divider()                    # โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
console.rule("Section Title")        # ------- Section Title -------
console.rule("Title", style="โ•")     # โ•โ•โ•โ•โ•โ•โ• Title โ•โ•โ•โ•โ•โ•โ•
console.blank(2)                     # 2 empty lines

๐Ÿ“Š Progress Bars

from xylogger import ProgressBar
import time

# Basic progress bar
with ProgressBar(total=100, description="Processing") as pb:
    for i in range(100):
        time.sleep(0.02)
        pb.update(1)

# Customized progress bar
with ProgressBar(
    total=50,
    description="Downloading",
    width=30,
    style="blocks",        # "default", "blocks", "arrows", "dots", "lines", "squares"
    show_percentage=True,
    show_count=True,
    show_eta=True
) as pb:
    for i in range(50):
        time.sleep(0.05)
        pb.update(1)

Available Styles:

Style Characters
default โ–ˆโ–‘
blocks โ–“โ–‘
arrows โ–ถโ”€
dots โ—โ—‹
lines โ”โ”€
squares โ– โ–ก

๐Ÿ”„ Spinners

from xylogger import Spinner
import time

# Basic spinner
with Spinner("Loading..."):
    time.sleep(2)

# Custom spinner
with Spinner(
    message="Processing data...",
    style="dots2",     # See styles below
    interval=0.1
) as spinner:
    time.sleep(3)
    spinner.stop("โœ“ Done!")

Available Styles:

Style Animation
dots โ ‹โ ™โ นโ ธโ ผโ ดโ ฆโ งโ ‡โ 
line -|/
dots2 โฃพโฃฝโฃปโขฟโกฟโฃŸโฃฏโฃท
arc โ—œโ— โ—โ—žโ—กโ—Ÿ
bounce โ โ ‚โ „โ ‚
circle โ—โ—“โ—‘โ—’
square โ—ฐโ—ณโ—ฒโ—ฑ
star โœถโœธโœนโœบโœนโœท
arrows โ†โ†–โ†‘โ†—โ†’โ†˜โ†“โ†™
clock ๐Ÿ•๐Ÿ•‘๐Ÿ•’...๐Ÿ•›

๐Ÿ“‹ Tables

from xylogger import Table

# Basic table
table = Table(["Name", "Age", "City"])
table.add_row(["Alice", "25", "New York"])
table.add_row(["Bob", "30", "Los Angeles"])
table.add_row(["Charlie", "35", "Chicago"])
table.print()

# Styled table
table = Table(
    headers=["Product", "Price", "Stock"],
    style="rounded",        # "default", "rounded", "double", "simple"
    padding=2
)
table.add_rows([
    ["Laptop", "$999", "15"],
    ["Mouse", "$29", "150"],
    ["Keyboard", "$79", "80"]
])
table.print()

Table Styles:

default:  โ”Œโ”€โ”€โ”ฌโ”€โ”€โ”    rounded: โ•ญโ”€โ”€โ”ฌโ”€โ”€โ•ฎ    double: โ•”โ•โ•โ•ฆโ•โ•โ•—    simple: +--+--+
          โ”‚  โ”‚  โ”‚             โ”‚  โ”‚  โ”‚            โ•‘  โ•‘  โ•‘            |  |  |
          โ”œโ”€โ”€โ”ผโ”€โ”€โ”ค             โ”œโ”€โ”€โ”ผโ”€โ”€โ”ค            โ• โ•โ•โ•ฌโ•โ•โ•ฃ            +--+--+
          โ””โ”€โ”€โ”ดโ”€โ”€โ”˜             โ•ฐโ”€โ”€โ”ดโ”€โ”€โ•ฏ            โ•šโ•โ•โ•ฉโ•โ•โ•            +--+--+

๐Ÿ“ฆ Panels (Boxed Content)

from xylogger import Panel

# Basic panel
panel = Panel("Hello, World!")
panel.print()

# Panel with title
panel = Panel(
    content="Welcome to Xylogger!\nThe ultimate logging library.",
    title="Welcome",
    style="rounded",    # "default", "rounded", "double", "heavy"
    padding=1
)
panel.print()

# Multi-line content
panel = Panel([
    "Line 1: First item",
    "Line 2: Second item",
    "Line 3: Third item"
], title="List")
panel.print()

โฑ๏ธ Timers

from xylogger import Timer
import time

# Context manager timer
with Timer("Database Query"):
    time.sleep(0.5)
# Output: โฑ Database Query: 500.12ms

# Access elapsed time
with Timer("Processing") as t:
    time.sleep(1)
    print(f"Elapsed so far: {t.elapsed}s")

๐Ÿ“ File Logging

from xylogger import Logger, FileHandler, RotatingFileHandler, JSONHandler

logger = Logger()

# Simple file handler
logger.add_handler(FileHandler("app.log"))

# Rotating file handler (max 10MB, keep 5 backups)
logger.add_handler(RotatingFileHandler(
    filename="app.log",
    max_bytes=10485760,  # 10 MB
    backup_count=5
))

# JSON handler for structured logging
logger.add_handler(JSONHandler("app.json"))

logger.info("This goes to all handlers")

File Output (app.log):

[2024-01-15 12:30:45] [INFO] This goes to all handlers

JSON Output (app.json):

{"timestamp": "2024-01-15T12:30:45", "level": "INFO", "message": "This goes to all handlers"}

๐ŸŽจ Colors & Themes

from xylogger import ConsoleColors, rgb, hex_to_rgb, Theme

# Use predefined colors
print(f"{ConsoleColors.RED}Red text{ConsoleColors.RESET}")
print(f"{ConsoleColors.GREEN}Green text{ConsoleColors.RESET}")
print(f"{ConsoleColors.CYAN}Cyan text{ConsoleColors.RESET}")

# Custom RGB colors
custom_color = rgb(255, 128, 0)  # Orange
print(f"{custom_color}Orange text{ConsoleColors.RESET}")

# From hex
r, g, b = hex_to_rgb("#FF5733")
print(f"{rgb(r, g, b)}Hex color{ConsoleColors.RESET}")

# Style combinations
print(f"{ConsoleColors.BOLD}{ConsoleColors.CYAN}Bold Cyan{ConsoleColors.RESET}")
print(f"{ConsoleColors.UNDERLINE}Underlined{ConsoleColors.RESET}")
print(f"{ConsoleColors.ITALIC}Italic text{ConsoleColors.RESET}")

Available Colors:

# Foreground
RED, GREEN, YELLOW, BLUE, CYAN, PURPLE, GRAY, WHITE
ORANGE, PINK, LIME, TEAL, INDIGO, VIOLET, CORAL, GOLD, SALMON, TURQUOISE

# Background
BG_RED, BG_GREEN, BG_YELLOW, BG_BLUE, BG_CYAN, BG_PURPLE, BG_GRAY, BG_WHITE

# Styles
BOLD, DIM, ITALIC, UNDERLINE, BLINK, REVERSE, HIDDEN, STRIKETHROUGH

Available Themes:

Theme.DRACULA    # Purple/cyan palette
Theme.NORD       # Blue/teal palette
Theme.MONOKAI    # Vibrant colors
Theme.GRUVBOX    # Warm retro colors
Theme.CATPPUCCIN # Pastel colors

๐Ÿ”ง Decorators & Utilities

Log Function Calls

from xylogger import log_calls, console

@log_calls(logger=console, include_args=True, include_result=True)
def add(a, b):
    return a + b

result = add(5, 3)
# Output:
# [DEBUG] Calling add(5, 3)
# [DEBUG] add returned 8

Time Functions

from xylogger import timer

@timer(name="Calculation")
def heavy_computation():
    return sum(range(1000000))

result = heavy_computation()
# Output: โฑ Calculation: 45.23ms

Retry on Failure

from xylogger.utils import retry

@retry(max_attempts=3, delay=1)
def unreliable_api_call():
    # This will retry up to 3 times
    response = requests.get("https://api.example.com")
    return response.json()

Context Logging

from xylogger import console, LogContext

with LogContext(console, "Database"):
    console.info("Connecting...")
    console.info("Query executed")
# Output:
# [-(12:30:45)-] [ โ— ] INFO  ยป  [Database] Connecting...
# [-(12:30:45)-] [ โ— ] INFO  ยป  [Database] Query executed

Text Utilities

from xylogger.utils import bold, italic, underline, colorize, truncate, indent
from xylogger import ConsoleColors

print(bold("Bold text"))
print(italic("Italic text"))
print(underline("Underlined text"))
print(colorize("Custom color", ConsoleColors.PURPLE))
print(truncate("Very long text here", 10))  # "Very lo..."
print(indent("Line 1\nLine 2", prefix="  > "))

๐Ÿ”ง Advanced Configuration

Custom Logger

from xylogger import Logger, FileHandler

logger = Logger(
    name="MyApp",
    level="INFO",      # DEBUG, INFO, SUCCESS, WARNING, ERROR, CRITICAL
    theme="DRACULA"
)

# Add multiple handlers
logger.add_handler(FileHandler("debug.log", level="DEBUG"))
logger.add_handler(FileHandler("errors.log", level="ERROR"))

# Set context for all messages
logger.set_context("UserService")
logger.info("User logged in")  # Shows [UserService] prefix

# Clear context
logger.clear_context()

Custom Level Formatter

from xylogger import Logger
from xylogger.formatters import LevelFormatter
from xylogger import ConsoleColors

formatter = LevelFormatter()
formatter.set_format("INFO", ConsoleColors.BLUE, "โ„น INFO", "โ—†")
formatter.set_format("SUCCESS", ConsoleColors.GREEN, "โœ“ OK", "โœ“")

logger = Logger()
logger.level_formatter = formatter
logger.info("Custom format!")

๐Ÿ“‹ Complete Example

from xylogger import (
    console, Logger, Table, Panel, ProgressBar, 
    Spinner, Timer, FileHandler
)
import time

# Create section header
console.section("๐Ÿš€ Xylogger Demo")

# Basic logging
console.info("Starting application...")
console.success("Configuration loaded")

# Show a panel
Panel("Welcome to the demo!", title="Hello").print()

# Display a table
table = Table(["Feature", "Status"], style="rounded")
table.add_row(["Logging", "โœ“"])
table.add_row(["Progress", "โœ“"])
table.add_row(["Tables", "โœ“"])
table.print()

# Progress bar
with ProgressBar(100, "Loading") as pb:
    for i in range(100):
        time.sleep(0.01)
        pb.update(1)

# Timer
with Timer("Processing"):
    time.sleep(0.5)

# Gradient text
console.gradient_print("โœจ All features working! โœจ", (255, 0, 255), (0, 255, 255))

console.success("Demo completed!")

๐Ÿ“š API Reference

Logger Methods

Method Description
info(message) Log info message
success(message) Log success message
warning(message) Log warning message
error(message, error=None) Log error with optional exception
debug(message) Log debug message
critical(message) Log critical message
section(title, start_rgb, end_rgb) Gradient section header
gradient_print(text, start_rgb, end_rgb) Gradient colored text
rule(title, style, color) Horizontal rule
divider(char, color) Simple divider line
blank(count) Print empty lines

Extras

Class Description
ProgressBar Animated progress indicator
Spinner Loading animation
Table Formatted table output
Timer Execution time measurement
Panel Boxed content display

Handlers

Handler Description
ConsoleHandler Terminal output
FileHandler Plain text file
RotatingFileHandler Size-based rotation
JSONHandler Structured JSON
MemoryHandler In-memory buffer

๐Ÿ“„ License

MIT License - see LICENSE for details.


Made with โค๏ธ by ZeoN

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

xylogger-2.1.0.tar.gz (23.2 kB view details)

Uploaded Source

Built Distribution

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

xylogger-2.1.0-py3-none-any.whl (20.4 kB view details)

Uploaded Python 3

File details

Details for the file xylogger-2.1.0.tar.gz.

File metadata

  • Download URL: xylogger-2.1.0.tar.gz
  • Upload date:
  • Size: 23.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.10

File hashes

Hashes for xylogger-2.1.0.tar.gz
Algorithm Hash digest
SHA256 abde079eec051b3095bd97e51465f2369c21c770545a238dec6dd272eef81ffa
MD5 17395841b0aac826668cdfd611b2029b
BLAKE2b-256 4476e596bcb1455576769cd04cb7d2f29eb14ae16664b48da2f3c41953fd7a2e

See more details on using hashes here.

File details

Details for the file xylogger-2.1.0-py3-none-any.whl.

File metadata

  • Download URL: xylogger-2.1.0-py3-none-any.whl
  • Upload date:
  • Size: 20.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.10

File hashes

Hashes for xylogger-2.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 af90f530ecbd011bdbf4c852dc68c7415ad013cc8d610608cbcddf121b0548b6
MD5 b05a760025e6ea2dc37884b55d3c5e65
BLAKE2b-256 116ae8d8ee8283c540b815a39c5352a6931988d000f98d3df306f7ec28401968

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