Skip to content

Commit

Permalink
Replaced printTime with dateTimeFormat
Browse files Browse the repository at this point in the history
  • Loading branch information
Bungeefan committed Aug 19, 2024
1 parent 5281ed0 commit ca1832e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
9 changes: 6 additions & 3 deletions lib/src/printers/simple_printer.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'dart:convert';

import '../ansi_color.dart';
import '../date_time_format.dart';
import '../log_event.dart';
import '../log_level.dart';
import '../log_printer.dart';
Expand Down Expand Up @@ -28,16 +29,18 @@ class SimplePrinter extends LogPrinter {
Level.fatal: const AnsiColor.fg(199),
};

final bool printTime;
final bool colors;

SimplePrinter({this.printTime = false, this.colors = true});
SimplePrinter({
super.dateTimeFormat = DateTimeFormat.none,
this.colors = true,
});

@override
List<String> log(LogEvent event) {
var messageStr = stringifyMessage(event.message);
var errorStr = event.error != null ? ' ERROR: ${event.error}' : '';
var timeStr = printTime ? 'TIME: ${event.time.toIso8601String()}' : '';
var timeStr = printTimestamp ? 'TIME: ${getTime(event.time)}' : '';
return ['${_labelFor(event.level)} $timeStr $messageStr$errorStr'];
}

Expand Down
7 changes: 4 additions & 3 deletions test/printers/simple_printer_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ void main() {
stackTrace: StackTrace.current,
);

var plainPrinter = SimplePrinter(colors: false, printTime: false);
var plainPrinter =
SimplePrinter(colors: false, dateTimeFormat: DateTimeFormat.none);

test('represent event on a single line (ignoring stacktrace)', () {
var outputs = plainPrinter.log(event);
Expand All @@ -37,13 +38,13 @@ void main() {
});

test('print time', () {
var printer = SimplePrinter(printTime: true);
var printer = SimplePrinter(dateTimeFormat: DateTimeFormat.iso8601);

expect(printer.log(event)[0], contains('TIME'));
});

test('does not print time', () {
var printer = SimplePrinter(printTime: false);
var printer = SimplePrinter();

expect(printer.log(event)[0], isNot(contains('TIME')));
});
Expand Down

0 comments on commit ca1832e

Please sign in to comment.