Skip to content

Commit

Permalink
Allow users to specify stdout and stderr in Logging plugin (#549)
Browse files Browse the repository at this point in the history
* Fix example in readme

* Allow users to specify stdout and stderr in Logging plugin
  • Loading branch information
abitofevrything authored Sep 16, 2023
1 parent e30a8ea commit cf5c17d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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('<TOKEN>', GatewayIntents.allUnprivileged);
final client = await Nyxx.connectGateway('<TOKEN>', GatewayIntents.allUnprivileged);
final botUser = await client.users.fetchCurrentUser();
Expand Down
17 changes: 15 additions & 2 deletions lib/src/plugin/logging.dart
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -30,14 +30,27 @@ 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,
this.stackTraceLevel = Level.SEVERE,
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;

Expand Down

0 comments on commit cf5c17d

Please sign in to comment.