write_logger 0.0.2
write_logger: ^0.0.2 copied to clipboard
Colored console and encrypted daily file logging for Flutter apps.
write_logger #
Colored console logging and daily file logging for Flutter apps, with optional encryption and automatic retention cleanup.
Features #
- Console logs with ANSI colors and optional emojis
- Daily log files (
log_yyyy-MM-dd.txt) - Optional pluggable encryption for file contents
- Automatic deletion of logs older than N days
- Level filtering via
minLevel - Tags for categorizing events (e.g.
cURL,Auth) - Extensible sinks (
addSink)
Getting started #
dependencies:
write_logger:
path: ../write_logger # or your git / pub.flutter-io.cn path
Source: github.com/fakeeh-tech/WriteLogger
See the full demo in example/: every log level, sample cURL, open file, and in-app viewer.
cd example
flutter run
Use a terminal so ANSI colors show up.
Usage #
import 'package:write_logger/write_logger.dart';
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
await WriteLogger.init(
WriteLoggerConfig(
minLevel: WriteLogLevel.debug, // optional, default: info
retentionDays: 7, // optional
enableConsole: true, // optional
enableFile: true, // optional
useColors: true, // optional
useEmojis: true, // optional
// encryption: MyEncryptionAdapter(), // optional
),
);
await WriteLogger.i('App started', tag: 'Bootstrap');
await WriteLogger.w('Slow network');
await WriteLogger.e('Failed', error: Exception('boom'));
}
Minimal init #
All config fields have defaults:
await WriteLogger.init();
Log a cURL from your app #
Build the cURL string in your HTTP layer (Dio interceptor, etc.), then pass it in. No special color is required — use a level + tag:
final curl = "curl -X POST "
"-H 'Content-Type: application/json' "
"-H 'Authorization: ***' "
"--data '{\"id\":1}' "
"'https://api.example.com/v1/items'";
await WriteLogger.d(curl, tag: 'cURL');
| Tip | Detail |
|---|---|
| Level | Prefer debug for routine requests; error when the call fails |
| Tag | Use cURL (or HTTP) so lines are easy to filter |
| Color | Same as the level (e.g. debug → blue); no curl-specific color |
| Secrets | Redact Authorization, cookies, and API keys before logging |
Custom encryption #
class MyEncryptionAdapter implements EncryptionAdapter {
@override
Future<String> encrypt(String plainText) async => /* ... */;
@override
Future<String> decrypt(String cipherText) async => /* ... */;
}
await WriteLogger.init(
WriteLoggerConfig(encryption: MyEncryptionAdapter()),
);
Levels #
| Helper | Level | Typical console color |
|---|---|---|
WriteLogger.t |
trace | gray |
WriteLogger.d |
debug | blue |
WriteLogger.i |
info | cyan |
WriteLogger.w |
warning | yellow |
WriteLogger.e |
error | red |
WriteLogger.security |
security | magenta |
WriteLogger.performance |
performance | green |
WriteLogger.validate |
validate | green |
WriteLogger.delete |
delete | yellow |
Or:
await WriteLogger.log('custom', level: WriteLogLevel.security);
Get today's file path #
final path = await WriteLogger.getLogFilePath();
// null on web, or when file logging is disabled
if (WriteLogger.supportsFileLogging) {
// mobile / desktop file logs available
}
Opening or sharing the file (OS viewer, share sheet) belongs in the host app. The example shows openLogFile() via open_filex and an in-app viewer.
Web (console-only) #
On Flutter web, dart:io is unavailable. The package still compiles and logs to the console; file sink, retention, and getLogFilePath() are skipped / return null even if enableFile: true.
Config reference #
| Field | Default | Notes |
|---|---|---|
minLevel |
WriteLogLevel.info |
Drop logs below this priority |
retentionDays |
7 |
Delete older daily files |
enableConsole |
true |
Colored print output |
enableFile |
true |
Daily files on disk |
useColors |
true |
ANSI colors in console |
useEmojis |
true |
Emoji prefix per level |
encryption |
null |
Plain text files if null |
directoryPath |
documents dir | Override for tests |
fileNamePrefix |
log_ |
log_2026-08-06.txt |
Pass host-app values (e.g. Remote Config retention days) into WriteLoggerConfig — this package does not depend on Firebase.
Example app #
The example/ project demonstrates:
- Every log helper and
WriteLogger.log()for allWriteLogLevelvalues - Log sample cURL — app-provided curl string logged with
tag: 'cURL' - Open file — open today’s log with the OS default app (
open_filex) - View in app — read and display log contents in a screen
License #
MIT. See LICENSE.
Additional information #
Designed for Flutter apps that need durable, optionally encrypted device logs plus colored console output during development. On web, logging is console-only.