zap static method
Zap a log message with optional tag and level.
For example to zap a message:
BoltLogger.zap('Electricity is in the air!');
The message can also be an Exception/Error, StackTrace or a List to zap all 3 types (Object?, Exception/Error, StackTrace). These will be passed to the logger.
BoltLogger.zap(['Electricity is in the air!', myException, stackTrace]);
Implementation
static void zap(Object? message, {String? tag, Level level = Level.INFO}) {
Object? msg;
Object? error;
StackTrace? stacktrace;
void zapMap(Object? value) {
if (value is Exception || value is Error && error == null) {
error = value;
} else if (value is StackTrace && stacktrace == null) {
stacktrace = value;
} else if (msg == null) {
msg = value;
} else {
final errorMessage =
'When zapping a list it can only contain one of each Exception/Error, StackTrace or Object?: $message';
assert(false, errorMessage);
error = AssertionError([errorMessage]);
msg = '';
stacktrace = StackTrace.empty;
}
}
if (message is List) {
for (final Object? value in message) {
zapMap(value);
}
} else {
zapMap(message);
}
Logger(tag ?? 'BoltLogger').log(level, msg, error, stacktrace);
}