Skip to content

Commit

Permalink
Add optional log file config option
Browse files Browse the repository at this point in the history
  • Loading branch information
redsolver committed Aug 26, 2023
1 parent 7933613 commit b981527
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
11 changes: 8 additions & 3 deletions bin/s5_server.dart
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,16 @@ void main(List<String> 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,
Expand All @@ -66,7 +70,8 @@ void main(List<String> arguments) async {
);
}

const defaultConfig = '''# ! Documentation: https://docs.sfive.net/install/config
const defaultConfig =
'''# ! Documentation: https://docs.sfive.net/install/config
name = "my-s5-node"
Expand Down
6 changes: 6 additions & 0 deletions lib/logger/console.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ class ConsoleLogger extends Logger {
final String prefix;
final bool format;

IOSink? sink;

ConsoleLogger({this.prefix = '', this.format = true});

@override
Expand All @@ -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
Expand All @@ -27,6 +30,7 @@ class ConsoleLogger extends Logger {
} else {
stderr.writeln('$prefix[ERROR] $s');
}
if (sink != null) sink!.writeln('[ERROR] $s');
}

@override
Expand All @@ -36,6 +40,7 @@ class ConsoleLogger extends Logger {
} else {
stdout.writeln(prefix + s);
}
if (sink != null) sink!.writeln(s);
}

@override
Expand All @@ -45,6 +50,7 @@ class ConsoleLogger extends Logger {
} else {
stderr.writeln('$prefix[warn] $s');
}
if (sink != null) sink!.writeln('[warn] $s');
}

@override
Expand Down

0 comments on commit b981527

Please sign in to comment.