PrintX_Logger - Advanced & Extensible Logging for Flutter
PrintX_Logger is a clean, full-featured, production-ready logging package for Flutter/Dart inspired by the best in the ecosystem. It combines ergonomic, print()-like usage with power features loved by professionals:
- Multiple output "sinks" (console, file, HTTP, DevTools)
- Extensible, colorized, JSON or custom formatters
- Fine-grained filtering (level, tag, predicate)
- Detailed caller info (file name, line number, method)
- Flutter and platform exception capture (integration with ErrorWidget and FlutterError)
- Modular, testable, and high performance
Features
- Log levels: trace, debug, info, warn, error, fatal (customizable)
- Multiple outputs: console, file (with rotation), HTTP, DevTools logging
- Formatters: out-of-the-box color, JSON, easy custom
- Caller info: print file, line, method in log lines
- Filters: level/tag/predicate filtering, global/per-sink
- No setup needed: just use PrintX() as drop-in print()
- Lazy evaluation: expensive strings evaluated only when enabled
- Flutter error integration: logs uncaught errors automatically
- Advanced: session/context data, log export for support, async file I/O
Getting Started
Installation
Add to your pubspec.yaml:
dependencies:
print_x: <latest_version>
Basic Usage
import 'package:printx/printx_logger.dart';
// Like print()! No config needed for console logs in dev
PrintX('Hello PrintX!');
// All levels, all simple:
PrintX.debug('Debug message');
PrintX.info('Information');
PrintX.warn('Heads up!');
PrintX.error('This went wrong', tag: 'network', error: exception);
// Include tag, error, context, etc:
PrintX.fatal(
'Fatal error!',
tag: 'init',
error: SomeException(),
context: {'platform': 'android'}
);
Show File Name & Line Number
PrintX logs will now include the location (file.dart:123) where the log is called:
[2025-10-01T10:52:03.001Z] [INFO] [HomePageState._incrementCounter @ lib/main.dart:44] Counter incremented
This is automatic. You do not need to pass this.
If you use a custom formatter, use the helper:
String? extractFileAndLine(StackTrace? trace);
// Returns "SomeClass.methodName @ lib/main.dart:17"
Advanced Usage
Full Init and Output Routing
// Optionally initialize PrintX for file/HTTP/DevTools
await PrintX.initialize(
minimumLevel: LogLevel.debug,
enableConsoleLogging: true,
enableFileLogging: true,
enableDeveloperLogging: true,
enableColorOutput: true,
captureFlutterErrors: true,
);
// For changing colors at runtime:
PrintX.setColorOutput(true);
Filtering
import 'package:printx/printx_logger.dart';
final logger = PrintX.getLogger('MyFeature');
logger.addFilter(LevelFilter(LogLevel.warn)); // Only warn and up!
logger.addFilter(TagFilter(includeTags: ['api', 'ui']));
Specialized Loggers
PrintX.api.info('API call');
PrintX.ui.debug('Widget clicked');
PrintX.db.warn('Database slow');
PrintX.auth.error('Login failed');
Export & Manage Logs
final path = await PrintX.exportLogs();
await PrintX.clearLogs();
await PrintX.dispose();
Example Output
[2025-10-01T10:52:03.001Z] [INFO] [HomePageState._incrementCounter @ lib/main.dart:44] Counter incremented
[2025-10-01T10:52:03.009Z] [ERROR] [AuthService.login @ lib/auth/auth_service.dart:87] Authentication failed
Error: Invalid credentials
Colors are automatic when supported; info, debug, warn, etc. have distinct emphasis. When not supported, output is always clean and readable.
FAQ
-
I don't see colors!
- Run in an ANSI-compatible terminal (not every IDE console).
PlatformUtils.supportsAnsiColorsmust return true.- You can force color for testing by adjusting PlatformUtils or terminal settings.
-
How do I show class/file/line only?
- PrintX now parses and outputs
[Class.method @ file.dart:line].
- PrintX now parses and outputs
-
Can I deeply filter or format log output?
- Yes! Add your own Formatters and Filters via the open API.
License
MIT © Flutter Community
PrintX – The only logger you'll need for serious, maintainable Flutter apps.
Made with ❤️ for developers who love clean, powerful tools.