write_logger
Version 0.0.4 — Colored console logging and daily file logging for Flutter apps, with optional encryption and automatic retention cleanup.
Features
- Console logs with ANSI colors and a box border per entry (
enableConsole: kDebugModeby default) - Daily log files (
log_yyyy-MM-dd.txt) with the same box layout - Optional pluggable encryption for file message contents (
AppEncryptionAdaptersample in example) — level / timestamp / tag stay plaintext - Automatic deletion of logs older than N days
- All log levels written (no min-level filter)
- Tags for categorizing events — any string (e.g.
cURL,Login cURL,Auth); no special colors or handling - Extensible sinks (
addSink)
Getting started
dependencies:
write_logger: ^0.0.4
# or path / git:
# write_logger:
# path: ../write_logger
Source: github.com/fakeeh-tech/WriteLogger
See CHANGELOG.md for release notes.
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:flutter/foundation.dart';
import 'package:write_logger/write_logger.dart';
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
await WriteLogger.init(
WriteLoggerConfig(
enableConsole: kDebugMode, // optional, default: kDebugMode
retentionDays: 7, // optional
enableFile: true, // optional
// encryption: AppEncryptionAdapter(), // optional — see example sample
),
);
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();
enableConsole defaults to kDebugMode (on in debug, off in release/profile). Colors are always applied when the console sink is active.
Log a cURL from your app
Build the cURL string in your HTTP layer (Dio interceptor, etc.), then pass it in. Color comes from the level only — the tag is a plain label for filtering:
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');
// or a more specific label:
await WriteLogger.d(curl, tag: 'Login cURL');
| Tip | Detail |
|---|---|
| Level | Prefer debug for routine requests; error when the call fails |
| Tag | Any string — e.g. cURL, Login cURL, HTTP. No special color or logic |
| Color | From the level only (e.g. WriteLogger.d → blue). Tag does not affect color |
| Secrets | Redact Authorization, cookies, and API keys before logging |
Custom encryption
Implement EncryptionAdapter in the host app and pass it to init. A full
copy-paste sample lives in
example/lib/app_encryption_adapter.dart.
import 'dart:convert';
import 'package:write_logger/write_logger.dart';
/// Sample only — replace with real AES / keystore crypto in production.
class AppEncryptionAdapter implements EncryptionAdapter {
static const _prefix = 'WL1:';
@override
Future<String> encrypt(String plainText) async {
final bytes = utf8.encode(plainText);
return '$_prefix${base64Encode(bytes)}';
}
@override
Future<String> decrypt(String cipherText) async {
if (!cipherText.startsWith(_prefix)) return cipherText;
final encoded = cipherText.substring(_prefix.length);
return utf8.decode(base64Decode(encoded));
}
}
await WriteLogger.init(
WriteLoggerConfig(encryption: AppEncryptionAdapter()),
);
Omit encryption (or pass null) for plain-text files.
When encryption is on, only the message body (plus error / stack) is
encrypted. Level, timestamp, and tag stay readable so you can scan the file
for [cURL], [Login cURL], [Auth], etc. without decrypting:
┌───────────────────────────────────
│ [DEBUG] [2026-08-10 11:54:00] [Login cURL] WL1:aGVsbG8...
└───────────────────────────────────
Log layout
Console and file use the same boxed layout:
┌───────────────────────────────────
│ [INFO] [2026-08-10 11:54:00] [BLOC TRANSITION] SplashBloc → ...
└───────────────────────────────────
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 (debug mode); file sink, retention, and getLogFilePath() are skipped / return null even if enableFile: true.
Config reference
| Field | Default | Notes |
|---|---|---|
enableConsole |
kDebugMode |
Colored print output |
retentionDays |
7 |
Delete older daily files |
enableFile |
true |
Daily files on disk |
encryption |
null |
Encrypts message body only; tag/level/ts stay plaintext |
directoryPath |
documents dir | Override for tests |
fileNamePrefix |
log_ |
log_2026-08-06.txt |
ANSI colors are always on for console output.
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 with any tag (demo uses
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
- Encryption sample —
AppEncryptionAdapter
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.
Current package version: 0.0.4.
Libraries
- write_logger
- Colored console + daily file logging for Flutter.