logger_rs 2.0.3
logger_rs: ^2.0.3 copied to clipboard
A beautiful Rust-style logger for Dart with colored output, precise file locations, tag-based logging for AI analysis, and clean formatting inspired by the Rust compiler.
Logger RS #
A Rust-style logger for Dart with colored output, precise file locations, and clean formatting inspired by the Rust compiler.
Installation #
dependencies:
logger_rs: ^2.0.3
Quick Start #
import 'package:logger_rs/logger_rs.dart';
void main() {
Log.d('Debug message'); // Cyan
Log.i('Info message'); // Green
Log.w('Warning message'); // Yellow
Log.e('Error message'); // Red
Log.f('Fatal message'); // Magenta
Log.t('Trace message'); // Gray
}
Log Levels #
| Level | Method | Color | Description |
|---|---|---|---|
| Trace | Log.t() |
Gray | Verbose debugging, method entry/exit |
| Debug | Log.d() |
Cyan | Development information |
| Info | Log.i() |
Green | General information |
| Warning | Log.w() |
Yellow | Potential issues |
| Error | Log.e() |
Red | Errors with optional stack traces |
| Fatal | Log.f() |
Magenta | Critical failures |
Output Examples #
Simple Messages #
TRACE: Entering function src/service.dart:10:3
DEBUG: Processing request src/controller.dart:25:5
INFO: Server started on port 8080 src/main.dart:15:3
WARNING: Deprecated API usage
--> src/legacy.dart:67:9
|
└─
ERROR: Connection failed
--> src/database.dart:45:12
|
└─
CRITICAL: System out of memory
--> src/core.dart:112:7
|
└─
With Error and Stack Trace #
try {
await riskyOperation();
} catch (error, stackTrace) {
Log.e('Operation failed', error: error, stackTrace: stackTrace);
}
ERROR: Operation failed
--> src/service.dart:45:12
|
= error: SocketException: Connection refused
1 | #0 Service.call (src/service.dart:45:12)
2 | #1 App.run (src/app.dart:23:5)
└─
With Objects (JSON) #
Log.i({'user': 'john', 'action': 'login'});
INFO: src/auth.dart:15:3
|
┌─
{
"user": "john",
"action": "login"
}
└─
Tag Logging (Advanced) #
Group related logs across your application and export them for debugging or AI analysis.
Basic Usage #
// Tag logs throughout your code
Log.tag('auth', 'User pressed login');
Log.tag('auth', 'Validating credentials', level: Level.INFO);
Log.tag('auth', {'email': 'user@example.com'});
// Export when needed
Log.export('auth');
Conditional Export #
// Export only if errors occurred
Log.export('auth', onlyOnError: true);
// Export based on custom condition
Log.export('auth', export: isDebugMode);
Export Output #
When you call Log.export('auth'), the output is Markdown formatted for AI analysis:
# Tag: auth
════════════════════════════════════════════════════════════════════════════════
> **Tag:** `auth`
> **Generated:** 2024-01-30 12:30:45
> **Entries:** 4 | **Errors:** 1
## Summary
- **ERROR**: 1
- **INFO**: 2
- **DEBUG**: 1
## Timeline
### 12:30:45.001 🔵 [DEBUG] auth_page.dart:23:7
User pressed login
### 12:30:45.015 🟢 [INFO] auth_controller.dart:45:9
Validating credentials
### 12:30:45.050 🔵 [DEBUG] auth_service.dart:32:7
```json
{
"email": "user@example.com"
}
12:30:46.200 🔴 [ERROR] auth_controller.dart:52:11 #
Login failed: Invalid credentials
Stack Trace
#0 AuthService.authenticate (auth_service.dart:45:5)
#1 AuthController.login (auth_controller.dart:52:11)
Exported by logger_rs
════════════════════════════
Copy the content between the separators and paste it into your LLM.
Save to File #
export returns the formatted Markdown string, so you can save it to a file:
final markdown = Log.export('auth');
if (markdown != null) {
File('debug_auth.md').writeAsStringSync(markdown);
}
// Export all tags to files
final allLogs = Log.exportAll();
for (final entry in allLogs.entries) {
File('${entry.key}_log.md').writeAsStringSync(entry.value);
}
Tag API #
| Method | Returns | Description |
|---|---|---|
Log.tag(name, msg) |
void |
Add log to tag |
Log.export(name) |
String? |
Export to console and return markdown |
Log.exportAll() |
Map<String, String> |
Export all tags, return map of results |
Log.clear(name) |
void |
Clear tag without exporting |
Log.clearAll() |
void |
Clear all tags |
Log.hasTag(name) |
bool |
Check if tag exists |
Log.hasErrors(name) |
bool |
Check if tag has errors |
Log.entryCount(name) |
int |
Get entry count |
Tags are automatically removed in release builds (zero overhead).
Platform Support #
Works on all Dart platforms with automatic color support:
- Flutter (iOS, Android, Web, Desktop)
- Dart VM / Native
- Web (WASM compatible)
License #
MIT License - see LICENSE for details.
Author #
JhonaCode - @JhonaCodes