Skip to main content

A custom logger package

Project description

LogMagix

LogMagix is a custom Python logging package that provides styled, colorful log messages for various logging levels, such as success, warning, failure, and more. It includes advanced features such as batch logging, file logging, customizable animated loaders, and ASCII art displays through the Home class, perfect for adding visual appeal to terminal-based applications.

🔥 Features

  • Enhanced Logging Levels: Support for LogLevel enumeration, including DEBUG, INFO, WARNING, SUCCESS, ERROR, and CRITICAL, allowing fine-grained control over log output.
  • Batch Logging Mode: Queue messages to batch display them at once.
  • File Logging: Optionally log messages to a file with rotating log handlers.
  • Color Customization: ANSI escape sequences for colorful terminal output.
  • Timestamped Messages: Precise logging with time-based messages.
  • Loader with Animation: Built-in animated loader for long-running operations with customizable text and style.
  • ASCII Art Display: Display ASCII art with custom messages, branding, or system information.
  • User Welcome: Personalized greetings in the ASCII art screen.

⚙️ Installation

Install LogMagix locally:

pip install .

Or via PyPI:

pip install logmagix

🔧 Usage

Importing the Package

from logmagix import Logger, Loader, Home, LogLevel

Logging

Initialize the Logger class and log messages at different levels. You can now also set the minimum log level, batch log messages, and write them to a file:

log = Logger(log_file="app.log", prefix="myapp/logs")

# Set minimum log level to control the output (optional)
log.set_min_level(LogLevel.INFO)

# Log levels
log.success("Operation completed successfully!")
log.failure("Something went wrong!")
log.warning("This is a warning!")
log.info("Informational log message")
log.debug("Debugging log message")
log.critical("Critical error encountered", exit_code=1)  # Exits after logging
log.message("Custom", "Custom message with prefix")

# Batch Logging Example
log.batch()  # Start batch mode
log.success("Batch message 1")
log.info("Batch message 2")
log.flush()  # Output all batched messages

File Logging

Save logs to a file with rotation options:

log = Logger(
    log_file="my_app.log",
    max_file_size=5_000_000,  # 5MB max file size
    backup_count=3            # Keep 3 backup files
)
log.info("Logging to file with rotation setup!")

Loading Animation

Use the Loader class in two ways:

  1. Context Manager:

    from time import sleep
    
    with Loader(desc="Loading data..."):
        sleep(2)
    
  2. Start/Stop Methods:

    loader = Loader(desc="Saving files...", end="Done!").start()
    sleep(2)
    loader.stop()
    

ASCII Art and Welcome Display

The Home class allows you to display ASCII art along with user greetings and system information.

home_screen = Home(
    text="LogMagix",
    align="center",
    adinfo1="logmagix.io",
    adinfo2="v1.2",
    credits="Developed by sexfrance"
)
home_screen.display()

Full Example

Here’s an example showing logging, loader, and the Home ASCII art functionality:

from logmagix import Logger, Loader, Home
import time

log = Logger(log_file="app.log", prefix="myapp")

# Logging
log.success("Everything is running smoothly!")
log.warning("This is just a warning!")
log.failure("A critical error occurred.")
log.debug("System debug message")

# Loader with context manager
with Loader(prefix="myapp/loader", desc="Processing data..."):
    time.sleep(2)

# ASCII Art Home screen
home_screen = Home(
    text="LogMagix",
    align="center",
    adinfo1="https://logmagix.io",
    adinfo2="v1.2",
    credits="Developed by sexfrance"
)
home_screen.display()

🛠️ Configuration Options

Logger

  • Log Levels: Control which levels to log using LogLevel enumeration, including DEBUG, INFO, WARNING, SUCCESS, ERROR, and CRITICAL. Set a minimum level to ignore lower-priority messages.
  • prefix: Custom prefix before each log message.
  • log_file: File path to log messages.
  • max_file_size: Maximum size for log files (default is 10MB).
  • backup_count: Number of backup log files to keep.

Loader

  • desc: Description displayed alongside the loading animation.
  • end: Text displayed after the loader stops.
  • timeout: Delay between animation frames (in seconds).

Home

  • text: ASCII text to display.
  • align: Text alignment in the terminal ("left", "center", "right").
  • adinfo1 / adinfo2: Additional info displayed below the ASCII art.
  • credits: Custom credits or developer name.

🖥️ Contributing

Contributions are welcome! To contribute:

  1. Fork the repository.
  2. Make your changes.
  3. Submit a pull request for review.

For major changes, please open an issue first to discuss what you’d like to change.

©️ License

LogMagix is licensed under the MIT License. See the LICENSE file for details.

👤 Author

LogMagix is developed and maintained by sexfrance.

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

logmagix-2.0.1.tar.gz (11.4 kB view details)

Uploaded Source

Built Distribution

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

logmagix-2.0.1-py3-none-any.whl (9.6 kB view details)

Uploaded Python 3

File details

Details for the file logmagix-2.0.1.tar.gz.

File metadata

  • Download URL: logmagix-2.0.1.tar.gz
  • Upload date:
  • Size: 11.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for logmagix-2.0.1.tar.gz
Algorithm Hash digest
SHA256 2c56598d12c27801cd1aa568a2a123ad1ab322aef38f60e6cdd35a4b1c07bd9a
MD5 76c2c33662d96d302d03f3fb43f54f50
BLAKE2b-256 75d45a35a196e8209efbb6ad64891d5c6ebbddcb6404e787b97147132c030e89

See more details on using hashes here.

File details

Details for the file logmagix-2.0.1-py3-none-any.whl.

File metadata

  • Download URL: logmagix-2.0.1-py3-none-any.whl
  • Upload date:
  • Size: 9.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for logmagix-2.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 fa107324a4ea9ecff50b4461cb0f9b9ba8e6d7524ba62606577eab3305dbc121
MD5 fd639df3c8d59683bf915cc823896e98
BLAKE2b-256 9e0013a91f9a17112af6aa995a13377bf81ab09406ad23196b6f11376ee3da39

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