Metadata-Version: 2.4
Name: logmagix-yuge
Version: 3.0.0
Summary: Beautiful & Simple Python Logger with Multi-threaded Multi-line Dynamic Logging Support
Home-page: https://github.com/yuge/logmagix-yuge
Author: Yuge
Author-email: Yuge <bwuuuuu@gmail.com>
License: MIT
Project-URL: Homepage, https://github.com/yuge/logmagix-yuge
Project-URL: Repository, https://github.com/yuge/logmagix-yuge
Project-URL: Bug Tracker, https://github.com/yuge/logmagix-yuge/issues
Keywords: logger,logging,colorful,multi-threaded,dynamic,progress
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Topic :: System :: Logging
Requires-Python: >=3.8
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: colorama
Requires-Dist: pystyle
Requires-Dist: packaging
Dynamic: author
Dynamic: home-page
Dynamic: license-file
Dynamic: requires-python

# LogMagix-Yuge

Beautiful & Simple Python Logger with Multi-threaded Multi-line Dynamic Logging Support

## 🚀 Quick Start

```python
from logmagix import Logger, LogLevel

# Choose your logging style (1 = ColorLogger, 2 = SimpleLogger)
log = Logger(
    style=1,  # Default colorful style
    prefix="MyApp",
    github_repository="https://github.com/sexfrance/logmagix",
    level=LogLevel.DEBUG,
    log_file="logs/app.log"  # Optional log file
)

# Basic logging
log.info("Hello World!")
log.success("Operation completed!")
log.warning("Something might be wrong")
log.error("An error occurred")
log.critical("Fatal error", exit_code=1)
```

## 🔥 Features

- **Multi-threaded Multi-line Dynamic Logging** - NEW in v3.0! Display multiple threads' progress simultaneously
- Log messages for various levels: success, warning, failure, debug, critical, info, and more
- Color customization using ANSI escape sequences
- Time-stamped log messages for better tracking
- Built-in animated loader for visually appealing loading spinners
- Thread-safe operations with automatic slot management
- Auto-expand slots and queue waiting for overflow handling
- Graceful fallback for non-TTY environments
- Log saving to file with optional log file paths
- Customizable log and loader prefixes
- ASCII art display for personalized greetings, system info, and branding
- Simple and flexible API with multiple ways to use the `Loader` class
- Customizable text alignment for the `Home` ASCII art display

## ⚙️ Installation

To install the package locally, clone the repository and run:

```bash
pip install .
```

You can also install it via `pip` from PyPI:

```bash
pip install logmagix-yuge
```

## 🔧 Usage

### Importing the Package

```python
from logmagix import Logger, Loader, Home
```

### Logging

Initialize the `Logger` class to log messages with different levels:

```python
log = Logger()

# Success message
log.success("Operation completed successfully!")

# Failure message
log.failure("Something went wrong!")

# Warning message
log.warning("This is a warning!")

# Informational message
log.info("Informational log message")

# Debug message
log.debug("Debugging log message")

# Critical message (also terminates the program with optional exit code)
log.critical("Critical failure encountered", exit_code=1)
```

### Log Levels

LogMagix provides several logging levels to help categorize the severity and type of log messages. You can configure the minimum log level to display based on your requirements:

- `DEBUG`: For detailed debug messages.
- `INFO`: For informational messages.
- `WARNING`: For warning messages.
- `SUCCESS`: For successful operations.
- `FAILURE`: For non-critical errors.
- `CRITICAL`: For critical errors; may terminate the program.

You can set the minimum logging level on initialization by passing a `LogLevel` value to the `Logger` constructor. For example:

```python
from logmagix import Logger, LogLevel

log = Logger(level=LogLevel.WARNING)
```

With this setting, only `WARNING`, `SUCCESS`, `FAILURE`, and `CRITICAL` messages will display.

## 🎨 Logging Styles

LogMagix offers two distinct logging styles:

### Style 1: ColorLogger (Default)

```python
log = Logger(style=1)  # or just Logger()
```

Features colorful, detailed output with customizable prefixes and ANSI color formatting.

### Style 2: SimpleLogger

```python
log = Logger(style=2)
```

Provides a minimalist, clean output format with basic color coding.

### Style Comparison

```python
# Style 1 (ColorLogger)
log1 = Logger(prefix="ColorLogger")
log1.success("Operation successful!")
# Output: [ColorLogger] [12:34:56] [Success] -> Operation successful!

# Style 2 (SimpleLogger)
log2 = Logger(style=2, prefix="SimpleLogger")
log2.success("Operation successful!")
# Output: 12:34:56 » SUCCESS ➔ Operation successful!
```

### Log File Saving

You can specify a log file path to save logs to a file for further review or debugging. The logger will automatically strip ANSI color codes from messages saved to the log file for readability. Log files are appended with each new logging session.

```python
log = Logger(log_file="logs/app.log")
log.success("This message will also be saved to app.log")
```

To view logs saved to the file, open the specified path and review the recorded entries, which include timestamped log messages for tracking system state over time.

## 🚀 Multi-threaded Multi-line Dynamic Logging (NEW in v3.0!)

The `MultiLineLoader` class allows you to display multiple threads' progress simultaneously, with each thread occupying its own line. Perfect for parallel task execution!

### Basic Usage

```python
from logmagix import MultiLineLoader
import threading
import time

# Method 1: Context Manager (Recommended)
with MultiLineLoader(slots=5, prefix="MyApp") as loader:
    def worker(task_name):
        handle = loader.reserve(task_name)
        handle.update("Initializing...")
        time.sleep(1)
        handle.update("Processing...")
        time.sleep(1)
        handle.done("Completed!")

    threads = []
    for i in range(5):
        t = threading.Thread(target=worker, args=(f"Task-{i+1}",))
        threads.append(t)
        t.start()

    for t in threads:
        t.join()

# Method 2: Manual Control
loader = MultiLineLoader(slots=3, auto_collapse=True).start()
handle = loader.reserve("Download")
handle.update("Downloading file...")
time.sleep(2)
handle.done("Download complete!")
loader.stop()
```

### Features

- **Thread-Safe**: All operations are protected with RLock and Condition
- **Dynamic Rendering**: Real-time updates with ANSI cursor control
- **Auto-Expand**: Automatically adds slots up to 80% of terminal height
- **Queue Waiting**: Threads wait for free slots when all are occupied
- **Status Icons**: ✓ (success), ✗ (failure), ⚠ (warning)
- **Auto-Collapse**: Optional automatic collapse when all tasks complete
- **Graceful Fallback**: Automatically switches to sequential logging in non-TTY environments

### Handle Methods

```python
handle = loader.reserve("TaskName")

# Update progress
handle.update("Processing step 1...")

# Mark as completed (green ✓)
handle.done("Task completed successfully!")

# Mark as failed (red ✗)
handle.fail("Task failed!")

# Mark with warning (yellow ⚠)
handle.warn("Task completed with warnings")
```

### Configuration Options

```python
loader = MultiLineLoader(
    slots=5,                    # Initial number of slots
    prefix="MyApp",             # Prefix for all lines
    refresh_rate=0.1,           # Refresh interval in seconds
    auto_collapse=False,        # Auto-collapse when all tasks complete
    auto_expand=True,           # Auto-expand slots when needed
    max_height_ratio=0.8,       # Max slots as ratio of terminal height
    logger=None                 # Optional Logger instance
)
```

## 🔄 Loading Animation

The Loader class now supports custom prefixes and can be used in two ways:

```python
from logmagix import Loader
import time

# Method 1: Context Manager
with Loader(
    prefix="MyApp",
    desc="Processing...",
    end="Completed!",
    timeout=0.1
):
    time.sleep(2)  # Your task here

# Method 2: Manual Control
loader = Loader(
    prefix="MyApp",
    desc="Loading...",
    end="Done!",
    timeout=0.05
).start()
time.sleep(2)  # Your task here
loader.stop()
```

## Custom Log and Loader Prefix

Both the `Logger` and `Loader` classes allow for customizing the prefix shown before each message:

#### Logger Prefix:

```python
log = Logger(prefix=".myapp/logs")
log.success("This message has a custom log prefix!")
```

#### Loader Prefix:

```python
loader = Loader(prefix=".myapp/loader", desc="Loading with a custom loader prefix...")
loader.start()
time.sleep(5)  # Simulate a task
loader.stop()
```

### ASCII Art and Greeting (New `Home` Class)

The `Home` class lets you display customized ASCII art text along with system information, such as a welcome message, username, or credits.

#### Using the `Home` Class:

```python
home_screen = Home(
    text="LogMagix",
    align="center",
    adinfo1="discord.cyberious.xyz",
    adinfo2="v1.0",
    credits="Developed by sexfrance",
    clear = False, # To clear the console, default is True
)

home_screen.display()
```

This will display the ASCII art version of "LogMagix" in the center of the terminal, along with optional `adinfo1` and `adinfo2` texts at the bottom. The terminal width is automatically detected to align the text properly.

### Full Example

Here’s an example showing both logging, loader, and the new `Home` class functionality:

```python
from logmagix import Logger, Home, Loader, LogLevel
import time
import uuid

# Test ColorLogger (Style 1 - Default)
log1 = Logger(
    prefix="ColorLogger",
    github_repository="https://github.com/sexfrance/LogMagix",
    level=LogLevel.DEBUG,
    log_file="logs/color.log"
)

start_time = time.time()
log1.success("We are running style 1!")
log1.warning("Watch out, something might happen!")
log1.failure("Critical error occurred!")
log1.info("System is working properly")
log1.debug(f"The system uuid is {uuid.getnode()}")
log1.message("Dad", f"How are you? I'm gonna come soon!", start=start_time, end=time.time())
log1.question("How old are you? ")

# Test SimpleLogger (Style 2)
log2 = Logger(
    style=2,
    prefix="SimpleLogger",
    level=LogLevel.INFO,
    log_file="logs/simple.log"
)

start_time = time.time()
log2.success("We are running style 2 !")
log2.info("System is working properly")
log2.error("Critical error occurred!")
log2.warning("Watch out, something might happen!")
log2.message("System is working properly")
log2.debug(f"The system uuid is {uuid.getnode()}")
log2.question("How old are you? ")

# Test loader with custom prefix and context manager
print("\nTesting Loader:")
with Loader(prefix="custom/loader/prefix", desc="Processing data..."):
    time.sleep(2)  # Simulate task

# Use loader with custom prefix and start/stop methods
loader = Loader(prefix="custom/loader/prefix", desc="Saving files...", end="Done !", timeout=0.05).start()
time.sleep(2)  # Simulate task
loader.stop()


# Display home screen
home_screen = Home(
    text="LogMagix",
    align="center",
    adinfo1="Test Suite",
    adinfo2="v1.0.0",
    credits="Testing Framework",
    clear=True
)
home_screen.display()

# Test critical error (commented out as it exits the program)
log1.critical("Critical error occurred!")
```

### Customization in `Home` Class

- **text**: The text to be displayed in ASCII art.
- **align**: Align the ASCII art text to "left", "center", or "right" in the terminal.
- **adinfo1** and **adinfo2**: Additional information displayed below the ASCII art.
- **credits**: Optional credits or user information.

### 📹 Preview

![Preview](https://i.imgur.com/fsgZuv1.png)

## ❗ Requirements

LogMagix requires:

- `colorama` for cross-platform color support in the terminal.
- `pystyle` for creating the colored text effects.

To install dependencies, run:

```bash
pip install colorama pystyle
```

## ©️ License

LogMagix is licensed under the MIT License. See the [LICENSE](LICENSE) file for more details.

## 🖥️ Contributing

Contributions are welcome! Feel free to fork the repository, make changes, and submit a pull request.

## 👤 Author

LogMagix is developed and maintained by **sexfrance**.

<p align="center">
  <img src="https://img.shields.io/github/license/sexfrance/LogMagix.svg?style=for-the-badge&labelColor=black&color=f429ff&logo=IOTA"/>
  <img src="https://img.shields.io/github/stars/sexfrance/LogMagix.svg?style=for-the-badge&labelColor=black&color=f429ff&logo=IOTA"/>
  <img src="https://img.shields.io/github/languages/top/sexfrance/LogMagix.svg?style=for-the-badge&labelColor=black&color=f429ff&logo=python"/>
  <img alt="PyPI - Downloads" src="https://img.shields.io/pypi/dm/logmagix?style=for-the-badge&labelColor=black&color=f429ff&logo=IOTA">

</p>
