From e822025613959bf58ab901aaf80fc898b2d87f57 Mon Sep 17 00:00:00 2001 From: "susa.keyber" Date: Sun, 1 May 2022 07:00:35 +0900 Subject: [PATCH] #1 fix: not return List, when only active execute close(), fix test --- lib/src/roggle.dart | 34 ++++++++++++++++++---------------- test/roggle_test.dart | 17 +++++++++++++---- 2 files changed, 31 insertions(+), 20 deletions(-) diff --git a/lib/src/roggle.dart b/lib/src/roggle.dart index 961c5de..bb82a01 100644 --- a/lib/src/roggle.dart +++ b/lib/src/roggle.dart @@ -42,37 +42,37 @@ class Roggle { bool get active => _active; /// Log a message at level [Level.verbose]. - List 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 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 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 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 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 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 log( + void log( Level level, Object message, [ Object? error, @@ -85,10 +85,9 @@ class Roggle { } else if (level == Level.nothing) { throw ArgumentError('Log events cannot have Level.nothing'); } - var output = []; 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); @@ -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(); diff --git a/test/roggle_test.dart b/test/roggle_test.dart index 7fe5786..aae65bc 100644 --- a/test/roggle_test.dart +++ b/test/roggle_test.dart @@ -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) { @@ -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', () {