mirror of
https://github.com/Yubico/yubioath-flutter.git
synced 2024-11-23 00:57:26 +03:00
Add timestamp to log entries.
This commit is contained in:
parent
9fae52b48b
commit
627e6bdadd
@ -4,6 +4,13 @@ import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:logging/logging.dart';
|
||||
|
||||
String _pad(int value, int zeroes) => value.toString().padLeft(zeroes, '0');
|
||||
|
||||
extension DateTimeFormat on DateTime {
|
||||
String get logFormat =>
|
||||
'${_pad(hour, 2)}:${_pad(minute, 2)}:${_pad(second, 2)}.${_pad(millisecond, 3)}';
|
||||
}
|
||||
|
||||
class Levels {
|
||||
/// Key for tracing information ([value] = 500).
|
||||
static const Level TRAFFIC = Level('TRAFFIC', 500);
|
||||
@ -45,7 +52,8 @@ class LogLevelNotifier extends StateNotifier<Level> {
|
||||
final List<String> _buffer = [];
|
||||
LogLevelNotifier() : super(Logger.root.level) {
|
||||
Logger.root.onRecord.listen((record) {
|
||||
_buffer.add('[${record.loggerName}] ${record.level}: ${record.message}');
|
||||
_buffer.add(
|
||||
'${record.time.logFormat} [${record.loggerName}] ${record.level}: ${record.message}');
|
||||
if (record.error != null) {
|
||||
_buffer.add('${record.error}');
|
||||
}
|
||||
|
@ -131,7 +131,8 @@ Future<Widget> initialize(List<String> argv) async {
|
||||
|
||||
void _initLogging(List<String> argv) {
|
||||
Logger.root.onRecord.listen((record) {
|
||||
stderr.writeln('[${record.loggerName}] ${record.level}: ${record.message}');
|
||||
stderr.writeln(
|
||||
'${record.time.logFormat} [${record.loggerName}] ${record.level}: ${record.message}');
|
||||
if (record.error != null) {
|
||||
stderr.writeln(record.error);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user