Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
125 changes: 104 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,32 +33,60 @@

Built with a modular Rust backend using PyO3/Maturin, Logly provides fast logging while maintaining memory safety and thread safety through Rust's ownership system.

> ⚠️ **Active Development**: Logly is actively developed. Performance continues to improve with each release.
**If you like Logly, please give it a star ⭐ on GitHub! It really helps!**

> ⚠️ **Active Development**: Logly is a newer project and actively developed. Performance continues to improve with each release. also if you find a bug or a missing feature, please report it on GitHub. and Logly is not Production Ready yet :)

> 📍 NOTE: The Main Branch Contains the latest features and improvements for upcoming releases. For stable production use, consider using the latest tagged release. because you may find an non existing feature or a bug in older releases.

> 📝 **Note on Loguru**: Logly is not the same as Loguru. Logly is only inspired by Loguru's design, but all features and functionality are completely different. Logly is built with Rust for performance and safety, while Loguru is a pure Python library.

### 🎯 Why Logly?

Logly combines the simplicity of Python with the performance and safety of Rust, providing:

- **High Performance**: Rust-powered backend with optimized data structures
- **Memory Safety**: No data races, guaranteed thread safety
- **Comprehensive Solution**: Full-featured logging with async, rotation, filtering, and callbacks
- **Developer Friendly**: Intuitive API inspired by Loguru
Logly offers a comprehensive set of logging features designed for modern Python applications:

### 🚀 Core Features

- **Rust-Powered Backend**: High-performance logging engine built with Rust, providing exceptional speed and memory efficiency
- **Memory Safety**: Zero-cost abstractions with Rust's ownership system prevent data races and memory corruption
- **Thread Safety**: Lock-free operations with optimized synchronization for concurrent applications
- **Zero-Configuration Setup**: Start logging immediately with sensible defaults - no configuration required

### 📝 Logging Capabilities

- **Multiple Log Levels**: Support for TRACE, DEBUG, INFO, SUCCESS, WARNING, ERROR, FAIL, and CRITICAL levels
- **Structured Logging**: Native JSON output with custom fields and metadata
- **Context Binding**: Attach persistent context to loggers for request tracking and correlation
- **Exception Handling**: Automatic exception logging with stack traces and context

### 🎯 Output Management

### ✨ Key Features
- **Multi-Sink Support**: Route logs to multiple destinations (console, files, custom handlers) simultaneously
- **Per-Sink Filtering**: Independent filtering and formatting for each output destination
- **Auto-Sink Levels**: Automatic file creation and management for different log levels
- **Console Control**: Fine-grained control over console output, colors, and timestamps per log level

- 🚀 **Rust-Powered Backend**: High-performance logging with async buffering
- 📦 **Modular Architecture**: Clean separation (backend, config, format, utils)
- 🔄 **Async Logging**: Background thread writing with configurable buffering
- 📋 **Structured JSON**: Native JSON support with custom fields and pretty printing
- 🎛️ **Per-Level Controls**: Fine-grained control over console output, timestamps, colors, and storage
- 🔧 **Smart Rotation**: Time-based (daily/hourly/minutely) and size-based rotation
- 🗜️ **Compression**: Built-in gzip and zstd compression for rotated files
- 🎯 **Multi-Sink**: Multiple outputs with independent filtering and formatting
- 🔍 **Rich Filtering**: Filter by level, module, or function name
- 📞 **Callbacks**: Custom log processing with async execution and color styling
- 🛡️ **Memory Safe**: Rust's ownership system prevents data races
- 🧵 **Thread Safe**: Lock-free operations with optimized synchronization
### 🔧 File Management

- **Smart Rotation**: Time-based (daily/hourly/minutely) and size-based log rotation
- **Compression**: Built-in gzip and zstd compression for rotated log files
- **Retention Policies**: Configurable retention periods and file count limits
- **Async Writing**: Background thread writing for non-blocking file operations

### 🔍 Advanced Filtering

- **Level-Based Filtering**: Filter logs by minimum severity level (threshold-based)
- **Module Filtering**: Include/exclude logs from specific Python modules
- **Function Filtering**: Target logs from specific functions or methods
- **Custom Filters**: Implement custom filtering logic with callback functions

### 📞 Callbacks & Extensions

- **Async Callbacks**: Real-time log processing with background execution
- **Custom Formatting**: Flexible template-based formatting with custom fields
- **Color Styling**: Rich color support for console output and callback processing
- **Extensibility**: Plugin architecture for custom sinks and processors and more...
---

## Installation
Expand All @@ -84,13 +112,55 @@ For detailed installation instructions, see the [Installation Guide](https://muh

---

## Platform Support

Logly supports Python 3.10+ and is available for multiple platforms. The minimum required version is **0.1.4+**.

| Python Version | Windows | macOS | Linux |
|----------------|---------|-------|-------|
| 3.10 | ✅ | ✅ | ✅ |
| 3.11 | ✅ | ✅ | ✅ |
| 3.12 | ✅ | ✅ | ✅ |
| 3.13 | ✅ | ✅ | ✅ |

**Notes:**
- All major Linux distributions are supported
- Both Intel and Apple Silicon macOS are supported
- Windows 10 and later versions are supported
- Pre-built wheels are available for all platforms ([view on PyPI](https://pypi.org/project/logly/#files))

---

## Quick Start

**NEW in v0.1.5:** Start logging immediately - no configuration needed!

```python
from logly import logger

# That's it! Start logging immediately
logger.info("Hello, Logly!") # ✅ Works right away
logger.warning("Super simple!") # ⚠️ No configure() needed
logger.error("Just import and log!") # ❌ Auto-configured on import

# Logs appear automatically because:
# - Auto-configure runs when you import logger
# - Console sink is created automatically (auto_sink=True)
# - Logging is enabled globally (console=True)
```

### Advanced Usage

```python
from logly import logger

# Add console output
logger.add("console")
# Optional: Customize configuration
logger.configure(
level="DEBUG", # Set minimum log level
color=True, # Enable colored output
console=True, # Enable console output (default: True)
auto_sink=True # Auto-create console sink (default: True)
)

# Add file output with rotation
logger.add(
Expand All @@ -101,6 +171,19 @@ logger.add(
async_write=True # Async writing for performance
)

# **NEW in v0.1.5:** Auto-Sink Levels - Automatic file management
logger.configure(
level="DEBUG",
color=True,
auto_sink=True, # Console output
auto_sink_levels={
"DEBUG": "logs/debug.log", # All logs (DEBUG and above)
"INFO": "logs/info.log", # INFO and above
"ERROR": "logs/error.log", # ERROR and above
}
)
# ✅ Three files created automatically with level filtering!

# Configure global settings
logger.configure(
level="INFO",
Expand Down
6 changes: 3 additions & 3 deletions SECURITY.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ We take security seriously and actively maintain security updates for the follow

| Version | Supported |
| ------- | ------------------ |
| 0.1.3+ | :white_check_mark: |
| < 0.1.3 | :x: |
| 0.1.4+ | :white_check_mark: |
| < 0.1.4 | :x: |

> **Note**: Versions below 0.1.3 lack many features that have been updated, improved, or removed. We strongly recommend always using the latest version for the best experience and security.

Expand Down Expand Up @@ -57,4 +57,4 @@ When using Logly in production:

## Contact

For security-related questions or concerns, please use the contact information above rather than creating public issues.
For security-related questions or concerns, please use the contact information above rather than creating public issues.
4 changes: 3 additions & 1 deletion docs/api-reference/complete-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ logger.configure(
time_levels: dict[str, bool] | None = None,
color_levels: dict[str, bool] | None = None,
storage_levels: dict[str, bool] | None = None,
color_callback: callable | None = None
color_callback: callable | None = None,
auto_sink: bool = True
) -> None
```

Expand All @@ -77,6 +78,7 @@ logger.configure(
| `color_levels` | `dict[str, bool] \| None` | `None` | Per-level color control. Example: `{"DEBUG": False}` disables colors for DEBUG logs. |
| `storage_levels` | `dict[str, bool] \| None` | `None` | Per-level file storage control. Example: `{"TRACE": False}` prevents TRACE from being written to files. |
| `color_callback` | `callable \| None` | `None` | Custom color function with signature `(level: str, text: str) -> str`. Overrides built-in ANSI coloring. Use for Rich, colorama, etc. |
| `auto_sink` | `bool` | `True` | Automatically create a console sink if no sinks exist. When `True` and no sinks have been added, a console sink is created automatically. This ensures logs are displayed even if you forget to add sinks. Set to `False` for full manual control. **WARNING**: If `auto_sink=True` and you try to add a console sink manually, you'll receive a duplicate sink warning |

#### Returns

Expand Down
35 changes: 30 additions & 5 deletions docs/api-reference/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ Methods for configuring the logger and managing output destinations.

Set global logger configuration including level, output format, and colors.

**NEW in v0.1.5**: The logger is automatically configured on import with default settings (`console=True`, `auto_sink=True`). This means you can start logging immediately without calling `configure()`. Calling `configure()` is optional and only needed if you want to customize the settings.

### Signature

```python
Expand All @@ -33,20 +35,22 @@ logger.configure(
time_levels: dict[str, bool] | None = None,
color_levels: dict[str, bool] | None = None,
storage_levels: dict[str, bool] | None = None,
color_callback: callable | None = None
color_callback: callable | None = None,
auto_sink: bool = True,
auto_sink_levels: dict[str, str | dict[str, str]] | None = None
) -> None
```

### Parameters

| Parameter | Type | Default | Description |
|-----------|------|---------|-------------|
| `level` | `str` | `"INFO"` | Minimum log level: `"TRACE"`, `"DEBUG"`, `"INFO"`, `"SUCCESS"`, `"WARNING"`, `"ERROR"`, `"CRITICAL"` |
| `color` | `bool` | `True` | Enable colored console output. When True, uses ANSI escape codes for coloring unless color_callback is provided. When False, disables all coloring regardless of other settings |
| `level_colors` | `dict[str, str] \| None` | `None` | Custom colors for each log level. Supports both ANSI color codes and color names. If `None`, uses default colors |
| `level` | `str` | `"INFO"` | Minimum log level: `"TRACE"`, `"DEBUG"`, `"INFO"`, `"SUCCESS"`, `"WARNING"`, `"ERROR"`, `"CRITICAL"`, `"FAIL"` |
| `color` | `bool` | `True` | Enable colored console output. When True, uses ANSI escape codes for coloring unless color_callback is provided. When False, disables all coloring regardless of other settings. Default colors: TRACE=cyan, DEBUG=blue, INFO=white, SUCCESS=green, WARNING=yellow, ERROR=red, CRITICAL=bright_red, FAIL=magenta |
| `level_colors` | `dict[str, str] \| None` | `None` | Custom colors for each log level. Supports both ANSI color codes and color names. If `None`, uses default color mapping (see above). Custom colors override defaults |
| `json` | `bool` | `False` | Output logs in JSON format instead of text |
| `pretty_json` | `bool` | `False` | Pretty-print JSON output (higher cost, more readable) |
| `console` | `bool` | `True` | Enable console output |
| `console` | `bool` | `True` | **Global enable/disable ALL logging** (kill-switch). When `True` (default), all logging is enabled across all sinks (console and file). When `False`, **ALL logging is disabled globally**, equivalent to calling `logger.disable()`. This is different from per-sink enable/disable which controls individual outputs |
| `show_time` | `bool` | `True` | Show timestamps in console output |
| `show_module` | `bool` | `True` | Show module information in console output |
| `show_function` | `bool` | `True` | Show function information in console output |
Expand All @@ -57,6 +61,8 @@ logger.configure(
| `color_levels` | `dict[str, bool] \| None` | `None` | Per-level color control. Maps level names to enable/disable colors |
| `storage_levels` | `dict[str, bool] \| None` | `None` | Per-level storage control. Maps level names to enable/disable file logging |
| `color_callback` | `callable \| None` | `None` | Custom color callback function with signature `(level: str, text: str) -> str`. When provided, overrides built-in ANSI coloring. Allows integration with external libraries like Rich, colorama, or termcolor for advanced coloring and styling |
| `auto_sink` | `bool` | `True` | **NEW in v0.1.5**: Automatically create a console sink if no sinks exist. Since v0.1.5, `configure()` is called automatically on import, so when `auto_sink=True` (default), a console sink is created immediately when you import the logger. This enables "import and log" workflow with zero configuration. Set to `False` if you want full manual control over sinks. **Note**: `auto_sink` only affects console sinks - file sinks are NEVER created automatically and must be added explicitly with `logger.add(file_path)` |
| `auto_sink_levels` | `dict[str, str \| dict[str, str]] \| None` | `None` | **NEW in v0.1.5**: Automatically configure per-level sinks using declarative configuration. Maps log level names to either sink type strings (`"console"`, `"file"`) or sink configuration dictionaries with `type` and `path` keys. See [Auto-Sink Levels Example](../examples/auto-sink-levels.md) for detailed usage |

### Color Configuration

Expand Down Expand Up @@ -140,6 +146,25 @@ def color_callback(level: str, text: str) -> str:

### Examples

=== "Default Colored Output (NEW v0.1.5)"

```python
from logly import logger

# Colors are automatic when color=True (default)
logger.configure(color=True)

# Each level gets its default color
logger.trace("Trace message") # Cyan
logger.debug("Debug info") # Blue
logger.info("Information") # White
logger.success("Success!") # Green
logger.warning("Warning!") # Yellow
logger.error("Error occurred") # Red
logger.critical("Critical!") # Bright Red
logger.fail("Operation failed") # Magenta (NEW)
```

=== "Text Output with Colors"

```python
Expand Down
25 changes: 25 additions & 0 deletions docs/api-reference/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@ Complete reference documentation for all Logly methods and features.

[Sink Management](sink-management.md)

- **Sink Control**

---

Enable/disable sinks and global logging control

[Sink Control](sink-control.md)

- **Logging**

---
Expand Down Expand Up @@ -78,6 +86,23 @@ Complete reference documentation for all Logly methods and features.

[File Operations](file-operations.md)

- **Log Search**

---

Search log files for specific strings

[:material-magnify: Search Functionality](search.md)
{ .md-button }

- **Troubleshooting**

---

Common issues and solutions

[Troubleshooting Guide](../guides/troubleshooting.md)

- **Utilities**

---
Expand Down
Loading