From cf5c17debddd7b021c26ab02a98d5c2c3d550ab7 Mon Sep 17 00:00:00 2001 From: Abitofevrything <54505189+abitofevrything@users.noreply.github.com> Date: Sat, 16 Sep 2023 07:20:45 -0700 Subject: [PATCH] Allow users to specify stdout and stderr in Logging plugin (#549) * Fix example in readme * Allow users to specify stdout and stderr in Logging plugin --- README.md | 2 +- lib/src/plugin/logging.dart | 17 +++++++++++++++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 3efffa197..21947bbf4 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ If you're already familiar with Discord's API, here's a quick example to get you import 'package:nyxx/nyxx.dart'; void main() async { - final client = await Nyxx.connectWebsocket('', GatewayIntents.allUnprivileged); + final client = await Nyxx.connectGateway('', GatewayIntents.allUnprivileged); final botUser = await client.users.fetchCurrentUser(); diff --git a/lib/src/plugin/logging.dart b/lib/src/plugin/logging.dart index c2dd7497d..a2ce512a2 100644 --- a/lib/src/plugin/logging.dart +++ b/lib/src/plugin/logging.dart @@ -1,5 +1,5 @@ import 'dart:async'; -import 'dart:io'; +import 'dart:io' as io; import 'package:logging/logging.dart'; import 'package:nyxx/src/api_options.dart'; @@ -30,6 +30,16 @@ class Logging extends NyxxPlugin { /// Whether to censor the token of clients this plugin is attached to. final bool censorToken; + /// The sink normal messages are sent to. + /// + /// Defaults to [io.stdout]. + final StringSink stdout; + + /// The sink error messages are sent to. + /// + /// Defaults to [io.stderr]. + final StringSink stderr; + /// Create a new instance of the [Logging] plugin. Logging({ this.stderrLevel = Level.WARNING, @@ -37,7 +47,10 @@ class Logging extends NyxxPlugin { this.logLevel = Level.INFO, this.truncateLogsAt = 1000, this.censorToken = true, - }); + StringSink? stdout, + StringSink? stderr, + }) : stdout = stdout ?? io.stdout, + stderr = stderr ?? io.stderr; static int _clients = 0;