Added logStream to logger. Updated example code.

Signed-off-by: Hans Kokx <hans.d.kokx@gmail.com>
This commit is contained in:
2025-04-28 17:41:52 +02:00
parent 6a28b8d90e
commit 3fd38d3b26
2 changed files with 189 additions and 81 deletions
@@ -29,6 +29,16 @@ class ArcaneLogger {
/// Additional metadata that is included in all logs.
Map<String, String> get additionalMetadata => I._additionalMetadata;
final StreamController<String> _logStreamController =
StreamController<String>.broadcast(
onCancel: () {
I._logStreamController.close();
},
);
/// Stream of log messages being received and sent to the registered interfaces.
Stream<String> get logStream => I._logStreamController.stream;
bool _initialized = false;
/// Whether the logger has been initialized.
@@ -241,6 +251,14 @@ class ArcaneLogger {
stackTrace: stackTrace,
extra: extra,
);
_logStreamController.add(
"$message ${{
"level": level,
"metadata": metadata,
"extra": extra,
}}",
);
}
}