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.0.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.0-py3-none-any.whl (9.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: logmagix-2.0.0.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.0.tar.gz
Algorithm Hash digest
SHA256 d9aa6d1dadca7313ec1bcdbf1e8cb5ec728c8ea13929a06da6219725f1f8c11a
MD5 3e510f5acee499c9b2f8563185896b69
BLAKE2b-256 ac665341d390d84afb25e1592f4c53649283b49534e37eb9a98096a570cc82cf

See more details on using hashes here.

File details

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

File metadata

  • Download URL: logmagix-2.0.0-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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 fee26ea7e7af2510e0fad457723c8736ed70dbf44bf6a424f351cd3d5d4e3dbd
MD5 f3cb911a657dfa3715e5b7f9df266e64
BLAKE2b-256 d08d0d987a59a7a90b5d1d93474979f3e6968870bdb427c63b7963a35107dff4

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