Skip to content

Namespaces and logging

import 'package:gisila_queue/gisila_queue.dart';

Every Redis or RabbitMQ component keeps its keys, queues and channels under a prefix. Two apps on the same Redis database or RabbitMQ vhost must use different prefixes; every component of one app must use the same one. See Namespaces.

abstract interface class Namespaced {
String get prefix;
}

Implemented by RedisBroker, RabbitBroker, RedisResultBackend, RedisControlChannel, RedisEventSink, RedisEventSource, RedisBeatLock and RedisBeatStateStore.

When to use: implement it on your own Redis-backed component so GisilaQueue and Beat include it in their prefix check.

const defaultNamespace = 'gq';

The prefix every component uses when none is given. Workers and beats running on it log defaultNamespaceWarning(...) at startup.

String? checkNamespaces(Map<String, Object?> components)

Returns the single prefix shared by the Namespaced values (and plain String values) in components, null if there are none, or throws ArgumentError listing each prefix when they differ. GisilaQueue and Beat call it in their constructors.

Symbol Description
defaultNamespaceWarning(String who) The warning text logged for a component on gq.

Minimal logging seam; the package has no logging dependency.

abstract class QueueLogger {
void log(LogLevel level, String message, {Object? error, StackTrace? stack});
void debug(String m);
void info(String m);
void warning(String m);
void error(String m, {Object? error, StackTrace? stack});
}

When to use: implement log to forward to your app’s logger, and pass it as GisilaQueue(logger: ...).

class ForwardingLogger extends QueueLogger {
ForwardingLogger(this.sink);
final void Function(String level, String message) sink;
@override
void log(LogLevel level, String message, {Object? error, StackTrace? stack}) =>
sink(level.name, error == null ? message : '$message: $error');
}
enum LogLevel { debug, info, warning, error }

Enqueue and retry-chain details are logged at debug; worker start/stop and successful tasks at info; retries, rejections, expiries at warning; failures at error.

class ConsoleQueueLogger extends QueueLogger {
ConsoleQueueLogger({LogLevel minLevel = LogLevel.info});
}

Default logger. Writes [gisila_queue] LEVEL message lines to stderr, with the cause and (for errors) the stack trace.

Drops everything. Use it in tests.

See also: GisilaQueue, Testing.