Add Logger.attachedLoggers to return the known Logger objects (#110)
Co-authored-by: Nate Bosch <nbosch@google.com>
diff --git a/CHANGELOG.md b/CHANGELOG.md
index e3023c7..6746eb4 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,7 @@
-## 1.0.3-dev
+## 1.1.0
+* Add `Logger.attachedLoggers` which exposes all loggers created with the
+ default constructor.
* Enable the `avoid_dynamic_calls` lint.
## 1.0.2
diff --git a/lib/src/logger.dart b/lib/src/logger.dart
index 026ec07..f702c73 100644
--- a/lib/src/logger.dart
+++ b/lib/src/logger.dart
@@ -51,8 +51,11 @@
/// root [Logger].
StreamController<LogRecord>? _controller;
- /// Singleton constructor. Calling `new Logger(name)` will return the same
- /// actual instance whenever it is called with the same string name.
+ /// Create or find a Logger by name.
+ ///
+ /// Calling `Logger(name)` will return the same instance whenever it is called
+ /// with the same string name. Loggers created with this constructor are
+ /// retained indefinitely and available through [attachedLoggers];
factory Logger(String name) =>
_loggers.putIfAbsent(name, () => Logger._named(name));
@@ -278,6 +281,11 @@
/// Top-level root [Logger].
static final Logger root = Logger('');
- /// All [Logger]s in the system.
+ /// All attached [Logger]s in the system.
static final Map<String, Logger> _loggers = <String, Logger>{};
+
+ /// All attached [Logger]s in the system.
+ ///
+ /// Loggers created with [Logger.detached] are not included.
+ static Iterable<Logger> get attachedLoggers => _loggers.values;
}
diff --git a/pubspec.yaml b/pubspec.yaml
index 003c4af..0fcd812 100644
--- a/pubspec.yaml
+++ b/pubspec.yaml
@@ -1,5 +1,5 @@
name: logging
-version: 1.0.3-dev
+version: 1.1.0
description: >-
Provides APIs for debugging and error logging, similar to loggers in other