Skip to content

Commit

Permalink
#1 fix: not return List<String>, when only active execute close(), fi…
Browse files Browse the repository at this point in the history
…x test
  • Loading branch information
susatthi committed Apr 30, 2022
1 parent 82cae23 commit e822025
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 20 deletions.
34 changes: 18 additions & 16 deletions lib/src/roggle.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,37 +42,37 @@ class Roggle {
bool get active => _active;

/// Log a message at level [Level.verbose].
List<String> v(Object message, [Object? error, StackTrace? stackTrace]) {
return log(Level.verbose, message, error, stackTrace);
void v(Object message, [Object? error, StackTrace? stackTrace]) {
log(Level.verbose, message, error, stackTrace);
}

/// Log a message at level [Level.debug].
List<String> d(Object message, [Object? error, StackTrace? stackTrace]) {
return log(Level.debug, message, error, stackTrace);
void d(Object message, [Object? error, StackTrace? stackTrace]) {
log(Level.debug, message, error, stackTrace);
}

/// Log a message at level [Level.info].
List<String> i(Object message, [Object? error, StackTrace? stackTrace]) {
return log(Level.info, message, error, stackTrace);
void i(Object message, [Object? error, StackTrace? stackTrace]) {
log(Level.info, message, error, stackTrace);
}

/// Log a message at level [Level.warning].
List<String> w(Object message, [Object? error, StackTrace? stackTrace]) {
return log(Level.warning, message, error, stackTrace);
void w(Object message, [Object? error, StackTrace? stackTrace]) {
log(Level.warning, message, error, stackTrace);
}

/// Log a message at level [Level.error].
List<String> e(Object message, [Object? error, StackTrace? stackTrace]) {
return log(Level.error, message, error, stackTrace);
void e(Object message, [Object? error, StackTrace? stackTrace]) {
log(Level.error, message, error, stackTrace);
}

/// Log a message at level [Level.wtf].
List<String> wtf(Object message, [Object? error, StackTrace? stackTrace]) {
return log(Level.wtf, message, error, stackTrace);
void wtf(Object message, [Object? error, StackTrace? stackTrace]) {
log(Level.wtf, message, error, stackTrace);
}

/// Log a message with [level].
List<String> log(
void log(
Level level,
Object message, [
Object? error,
Expand All @@ -85,10 +85,9 @@ class Roggle {
} else if (level == Level.nothing) {
throw ArgumentError('Log events cannot have Level.nothing');
}
var output = <String>[];
final logEvent = LogEvent(level, message, error, stackTrace);
if (_filter.shouldLog(logEvent)) {
output = _printer.log(logEvent);
final output = _printer.log(logEvent);

if (output.isNotEmpty) {
final outputEvent = OutputEvent(level, output);
Expand All @@ -97,11 +96,14 @@ class Roggle {
_output.output(outputEvent);
}
}
return output;
}

/// Closes the logger and releases all resources.
void close() {
if (!_active) {
return;
}

_active = false;
_filter.destroy();
_printer.destroy();
Expand Down
17 changes: 13 additions & 4 deletions test/roggle_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,15 @@ void main() {
printedStackTrace = null;
});

test('Roggle.log', () {
var logger = Roggle(filter: _NeverFilter(), printer: callbackPrinter)
..log(Level.debug, 'Some message');
test('Constructor', () {
Roggle(filter: _NeverFilter(), printer: callbackPrinter)
.log(Level.debug, 'Some message');

expect(printedMessage, null);
});

logger = Roggle(filter: _AlwaysFilter(), printer: callbackPrinter);
test('Roggle.log', () {
final logger = Roggle(filter: _AlwaysFilter(), printer: callbackPrinter);

final levels = Level.values.take(6);
for (final level in levels) {
Expand Down Expand Up @@ -94,6 +96,13 @@ void main() {
throwsArgumentError,
);
expect(() => logger.log(Level.nothing, 'Test'), throwsArgumentError);

logger.close();
expect(() => logger.log(Level.verbose, 'Test'), throwsArgumentError);

// Execute close() twice
logger.close();
expect(() => logger.log(Level.verbose, 'Test'), throwsArgumentError);
});

test('Roggle.v', () {
Expand Down

0 comments on commit e822025

Please sign in to comment.