diff --git a/bin/s5_server.dart b/bin/s5_server.dart index 43f6933..b30e1ea 100644 --- a/bin/s5_server.dart +++ b/bin/s5_server.dart @@ -45,12 +45,16 @@ void main(List arguments) async { ); } + final config = (await TomlDocument.load(file.path)).toMap(); + if (config['logger']?['file'] != null) { + logger.sink = File(config['logger']['file']!) + .openWrite(mode: FileMode.writeOnlyAppend); + } + logger.info(''); logger.info('s5-dart'.green().bold() + ' ' + 'v$nodeVersion'.red().bold()); logger.info(''); - final config = (await TomlDocument.load(file.path)).toMap(); - final node = S5Node( config, logger: logger, @@ -66,7 +70,8 @@ void main(List arguments) async { ); } -const defaultConfig = '''# ! Documentation: https://docs.sfive.net/install/config +const defaultConfig = + '''# ! Documentation: https://docs.sfive.net/install/config name = "my-s5-node" diff --git a/lib/logger/console.dart b/lib/logger/console.dart index 8ed2c3b..5631e23 100644 --- a/lib/logger/console.dart +++ b/lib/logger/console.dart @@ -7,6 +7,8 @@ class ConsoleLogger extends Logger { final String prefix; final bool format; + IOSink? sink; + ConsoleLogger({this.prefix = '', this.format = true}); @override @@ -18,6 +20,7 @@ class ConsoleLogger extends Logger { prefix + s.replaceAll(RegExp('\u001b\\[\\d+m'), ''), ); } + if (sink != null) sink!.writeln(s.replaceAll(RegExp('\u001b\\[\\d+m'), '')); } @override @@ -27,6 +30,7 @@ class ConsoleLogger extends Logger { } else { stderr.writeln('$prefix[ERROR] $s'); } + if (sink != null) sink!.writeln('[ERROR] $s'); } @override @@ -36,6 +40,7 @@ class ConsoleLogger extends Logger { } else { stdout.writeln(prefix + s); } + if (sink != null) sink!.writeln(s); } @override @@ -45,6 +50,7 @@ class ConsoleLogger extends Logger { } else { stderr.writeln('$prefix[warn] $s'); } + if (sink != null) sink!.writeln('[warn] $s'); } @override