Skip to content

Commit

Permalink
[server] Omit microseconds in log timestamps
Browse files Browse the repository at this point in the history
The default time stringization only includes microseconds if nonzero, which can make the logs look inconsistent, and the microseconds are a bit noisy anyway, so truncate them.
  • Loading branch information
AsturaPhoenix committed Aug 4, 2023
1 parent bb146ff commit 7627e8c
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion server/bin/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,16 @@ import 'package:shelf_router/shelf_router.dart';

void initializeLogger() {
Logger.root.onRecord.listen((record) {
final message = '[${record.time.toUtc()}] ${record.level} '
// The default stringization is at microsecond resolution but omits the
// microsegment fragment if the microseconds part is 0. Both the
// inconsistency and the microseconds themselves are not ideal in the logs,
// so let's truncate them.
final formattedTime = DateTime.fromMillisecondsSinceEpoch(
record.time.millisecondsSinceEpoch,
isUtc: true,
).toString();

final message = '[$formattedTime] ${record.level} '
'${record.loggerName}: ${record.message}';

if (record.level >= Level.WARNING ||
Expand Down

0 comments on commit 7627e8c

Please sign in to comment.