Skip to content

Commit 03be544

Browse files
committed
Deprecate callbacks
Nothing of what the callbacks offered couldn't be done by custom printers/outputs. Removing the callbacks simplifies the code.
1 parent a3c2cc3 commit 03be544

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

lib/src/logger.dart

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,10 @@ class OutputEvent {
3333
OutputEvent(this.level, this.lines);
3434
}
3535

36+
@Deprecated("Use a custom LogFilter instead")
3637
typedef LogCallback = void Function(LogEvent event);
38+
39+
@Deprecated("Use a custom LogOutput instead")
3740
typedef OutputCallback = void Function(OutputEvent event);
3841

3942
/// Use instances of logger to send log messages to the [LogPrinter].
@@ -43,7 +46,9 @@ class Logger {
4346
/// All logs with levels below this level will be omitted.
4447
static Level level = Level.verbose;
4548

49+
// NOTE: callbacks are soon to be removed
4650
static final Set<LogCallback> _logCallbacks = Set();
51+
// NOTE: callbacks are soon to be removed
4752
static final Set<OutputCallback> _outputCallbacks = Set();
4853

4954
final LogFilter _filter;
@@ -112,13 +117,15 @@ class Logger {
112117
}
113118
var logEvent = LogEvent(level, message, error, stackTrace);
114119
if (_filter.shouldLog(logEvent)) {
120+
// NOTE: callbacks are soon to be removed
115121
for (var callback in _logCallbacks) {
116122
callback(logEvent);
117123
}
118124
var output = _printer.log(logEvent);
119125

120126
if (output.isNotEmpty) {
121127
var outputEvent = OutputEvent(level, output);
128+
// NOTE: callbacks are soon to be removed
122129
for (var callback in _outputCallbacks) {
123130
callback(outputEvent);
124131
}
@@ -136,25 +143,29 @@ class Logger {
136143
}
137144

138145
/// Register a [LogCallback] which is called for each new [LogEvent].
146+
@Deprecated("Use a custom LogFilter instead")
139147
static void addLogListener(LogCallback callback) {
140148
_logCallbacks.add(callback);
141149
}
142150

143151
/// Removes a [LogCallback] which was previously registered.
144152
///
145153
/// Returns wheter the callback was successfully removed.
154+
@Deprecated("Use a custom LogFilter instead")
146155
static bool removeLogListener(LogCallback callback) {
147156
return _logCallbacks.remove(callback);
148157
}
149158

150159
/// Register an [OutputCallback] which is called for each new [OutputEvent].
160+
@Deprecated("Use a custom LogOutput instead")
151161
static void addOutputListener(OutputCallback callback) {
152162
_outputCallbacks.add(callback);
153163
}
154164

155165
/// Removes a [OutputCallback] which was previously registered.
156166
///
157167
/// Returns wheter the callback was successfully removed.
168+
@Deprecated("Use a custom LogOutput instead")
158169
static void removeOutputListener(OutputCallback callback) {
159170
_outputCallbacks.remove(callback);
160171
}

0 commit comments

Comments
 (0)