Logging
misskey_client can log HTTP requests and responses. Logging is disabled by default.
Enabling logs
Set enableLog: true in MisskeyClientConfig:
final client = MisskeyClient(
config: MisskeyClientConfig(
baseUrl: Uri.parse('https://misskey.example.com'),
enableLog: true,
),
tokenProvider: () => 'token',
);
When enabled, the default StdoutLogger writes to stdout via the logger package.
Disabling logs
Omit enableLog or set it to false (the default):
final client = MisskeyClient(
config: MisskeyClientConfig(
baseUrl: Uri.parse('https://misskey.example.com'),
enableLog: false, // default
),
);
Custom logger with FunctionLogger
FunctionLogger adapts a simple callback to the Logger interface:
final client = MisskeyClient(
config: MisskeyClientConfig(
baseUrl: Uri.parse('https://misskey.example.com'),
enableLog: true,
),
tokenProvider: () => 'token',
logger: FunctionLogger((level, message) {
// level is one of: 'debug', 'info', 'warn', 'error'
myLogger.log(level, message);
}),
);
A custom logger replaces the default StdoutLogger, but it does not bypass enableLog: it receives log calls only while enableLog is true.
Implementing a custom Logger
For full control, implement the Logger interface:
class MyLogger implements Logger {
void debug(String message) { /* ... */ }
void info(String message) { /* ... */ }
void warn(String message) { /* ... */ }
void error(String message, [Object? error, StackTrace? stackTrace]) {
// Handle error with optional stack trace
}
}
final client = MisskeyClient(
config: MisskeyClientConfig(
baseUrl: Uri.parse('https://misskey.example.com'),
enableLog: true,
),
tokenProvider: () => 'token',
logger: MyLogger(),
);
Default behavior
When enableLog: true is set and no custom logger is supplied, the StdoutLogger is used. It delegates to the logger package internally.
HTTP request, response, and retry logs are emitted only when enableLog is true and the app is not a release build. The default StdoutLogger uses the logger package's development filter, which suppresses all output when assertions are disabled (as in release builds). Streaming log calls depend only on enableLog, so a custom logger can receive them in release builds as well.
Log format:
[misskey_client] [LEVEL] 2025-01-01 12:00:00.000000 message