Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow users to specify stdout and stderr in Logging plugin #549

Merged
merged 2 commits into from
Sep 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading