From b7300d58cc1faf444b595dfa598c5c09cf59e232 Mon Sep 17 00:00:00 2001 From: Abdullah <89297042+AzazelSensei@users.noreply.github.com> Date: Sat, 5 Sep 2026 18:20:18 +0000 Subject: [PATCH 1/2] docs: add FileOutput date-based example Show writing logs to log-YYYY-M-D.txt in the README. --- README.md | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/README.md b/README.md index ab885dc..2004151 100644 --- a/README.md +++ b/README.md @@ -180,6 +180,26 @@ Other provided `LogOutput`s are: * `FileOutput`/`AdvancedFileOutput` * `StreamOutput` +### File output + +`FileOutput` writes logs to a file. Use the current date in the file name to get one +file per day (`log-2024-2-1.txt`, `log-2024-2-2.txt`, ...): + +```dart +import 'dart:io'; + +final date = DateTime.now(); +final logger = Logger( + printer: PrettyPrinter(colors: false), + output: FileOutput( + file: File('log-${date.year}-${date.month}-${date.day}.txt'), + ), +); +``` + +The file name is chosen when the `Logger` is created. For size-based rotation and +buffered writes, use `AdvancedFileOutput`. File output is not available on web. + Possible future `LogOutput`s could send to Firebase or to Logcat. Feel free to open pull requests. From 7e91438d350046d712c1ba57e2197cdf9887b2b6 Mon Sep 17 00:00:00 2001 From: Abdullah <89297042+AzazelSensei@users.noreply.github.com> Date: Sat, 5 Sep 2026 19:50:48 +0000 Subject: [PATCH 2/2] docs: use DateTimeFormat.onlyDate in FileOutput example ISO 8601 date in the file name. Note that the path is fixed at Logger creation. --- README.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 2004151..c8976a7 100644 --- a/README.md +++ b/README.md @@ -182,23 +182,23 @@ Other provided `LogOutput`s are: ### File output -`FileOutput` writes logs to a file. Use the current date in the file name to get one -file per day (`log-2024-2-1.txt`, `log-2024-2-2.txt`, ...): +`FileOutput` writes logs to a file. Include today's date in the file name +(`log-2024-02-01.log`, `log-2024-02-02.log`, ...): ```dart import 'dart:io'; -final date = DateTime.now(); final logger = Logger( printer: PrettyPrinter(colors: false), output: FileOutput( - file: File('log-${date.year}-${date.month}-${date.day}.txt'), + file: File('log-${DateTimeFormat.onlyDate(DateTime.now())}.log'), ), ); ``` -The file name is chosen when the `Logger` is created. For size-based rotation and -buffered writes, use `AdvancedFileOutput`. File output is not available on web. +The path is fixed when the `Logger` is created, so a process that stays up past +midnight keeps writing to the same file. For size-based rotation and buffered +writes, use `AdvancedFileOutput`. File output is not available on web. Possible future `LogOutput`s could send to Firebase or to Logcat. Feel free to open pull requests.