Skip to content

Commit

Permalink
Add Logger.attachedLoggers to return the known Logger objects (dart-a…
Browse files Browse the repository at this point in the history
…rchive#110)

Co-authored-by: Nate Bosch <[email protected]>
  • Loading branch information
powerb33 and natebosch authored Feb 16, 2022
1 parent dfbe88b commit f6979e3
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
14 changes: 11 additions & 3 deletions lib/src/logger.dart
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,11 @@ class Logger {
/// 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));

Expand Down Expand Up @@ -278,6 +281,11 @@ class Logger {
/// 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;
}
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit f6979e3

Please sign in to comment.