pd_log 0.9.0
pd_log: ^0.9.0 copied to clipboard
Cross-platform Flutter logging with pure Dart; buffered file writes; no platform channels.
pd_log #
Lightweight, cross-platform Flutter logging plugin with unified Dart file buffering and platform event listening.
Features #
- Multi-level logging:
PDLog.v/d/i/w/e, JSON pretty-print, ANSI styling. - Dart file buffering: Cross-platform unified write thread buffering with timed/threshold flush; platform side provides console output, root path, and directory event listening.
- File query & maintenance: List/delete logs, rotation cleanup, organize by year/month/day.
- Metadata tracking: Event ledger (NDJSON) and snapshot (JSON) auto-maintenance.
- Cross-platform unified: Web console output (no file writes), consistent API.
Platform Support #
| Platform | Support | Notes |
|---|---|---|
| Android | ✅ | File logging, console output, file events (polling) |
| iOS | ✅ | File logging, console output, file events (polling) |
| macOS | ✅ | File logging, console output, file events (watcher) |
| Windows | ✅ | File logging, console output, file events (watcher) |
| Linux | ✅ | File logging, console output, file events (watcher) |
| Web | ⚠️ | Console output only, no file system access |
Installation & Quick Start #
dependencies:
pd_log: ^0.9.0
import 'package:pd_log/pd_log.dart';
void main() {
PDLog.configure(const PDLogConfig(
minLevel: LogLevel.debug,
// Console colors: disabled by default
ansiEnabled: true,
fileLoggingEnabled: true,
));
PDLog.i('pd_log is ready');
}
Configuration notes:
fileLoggingEnabled: Enable local file writing (Dart-managed, unified buffering and flush); no-op on Web.ansiEnabled: Whether to wrap console output with ANSI colors (defaultfalse). File writes are always plain text.
Example: Disable ANSI for Apple console (plain text output):
import 'dart:io';
PDLog.updateConfigure(ansiEnabled: !(Platform.isIOS || Platform.isMacOS));
Key API (Selected) #
- Log output:
PDLog.v/d/i/w/e(Object? message, {String? tag}) - Flush buffer:
PDLog.flushLogs()(triggers Dart writer flush) - Query logs:
PDLog.listLogFiles(...),listLogFilesByYear(...),listLogFilesByYearMonth(...)(supportsListOptionssorting and pagination) - File path:
PDLog.logFilePathIfExists(DateTime date) - Read file:
PDLog.readLogFileContent(String path)(Dart file reading) - Metadata view:
PDLog.metaLedgerContent(),PDLog.metaSummaryContent() - Directory structure:
PDLog.fileTreeString({int maxDepth = 6})
Documentation #
Architecture overview: Dart manages all logging operations including console output, file writing, and buffering. Platform service provides log root path and file event listening. File enumeration, deletion, and search are fully implemented in Dart; Web platform gracefully degrades to console-only output.
Detailed usage instructions, notes, and best practices are available in the documentation module:
- Documentation index: doc/README.md
- Specific documentation links:
- Getting Started
- Configuration
- File Storage & Rotation
- Query & Pagination
- Metadata & History
- Web Platform Differences
- Styling & Formatting
- File Reading Tools
- Buffer Flush & Event Listening
Example Project #
Minimal example located in example/ directory, runnable with flutter run.
License #
MIT (see root LICENSE).