BDLogger class

BDLogger is a singleton class used for logging in Dart/Flutter applications.

It provides methods to log messages at different levels (debug, info, warning, success, error).

It supports multiple log handlers to handle log records in different ways (e.g., writing to a file, sending to a server).

The processing interval and chunk size can be changed dynamically, allowing developers to adjust the logger's performance at runtime.

The class provides a stream of BDLogError that occurred during logging, allowing developers to handle logging errors in a centralized way.

Here's an example of how to use this class:

final logger = BDLogger();
logger.addHandler(ConsoleLogHandler());
logger.log(BDLevel.info, 'Hello, world!');

If an error occurs while a log handler is processing a log record, the error is caught and added to the error stream. You can listen to this stream to handle logging errors:

logger.onError.listen((error) {
  // Handle the error.
});

When you're done with the logger, you should call the destroy method to clean up resources:

logger.destroy();

Constructors

BDLogger.new()
Returns the singleton instance of the BDLogger class.
factory
BDLogger.private(Set<BDLogHandler> _handlers, StreamController<BDLogError> _errorController, [int _processingBatchSize = defaultProcessingBatchSize])
Private constructor used to create the singleton instance of the class. This constructor is marked as @visibleForTesting to allow it to be accessed in tests.

Properties

handlers List<BDLogHandler>
Returns a list of the log handlers that are currently added to the logger.
no setter
hashCode int
The hash code for this object.
no setterinherited
onError Stream<BDLogError>
Returns a stream that emits BDLogError instances whenever an error occurs during logging.
no setter
processingBatchSize int
Returns the number of log records that are processed at a time.
getter/setter pair
processingTask Completer<void>?
A completer that is used to control the processing of log records.
getter/setter pair
recordQueue Queue<BDLogRecord>
A queue of log records that are waiting to be processed.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

addHandler(BDLogHandler handler) → void
Adds a log handler to the logger. The handler will be used to process log records.
debug(String message, {dynamic error, bool? isFatal, StackTrace? stackTrace, String? tag}) → void
Logs a message at the debug level. The message can optionally be associated with an error and a stack trace.
destroy() Future<void>
Destroys the singleton instance of the BDLogger class. This also calls the clean method on every BDCleanableLogHandler.
error(String message, Object error, {bool? isFatal, StackTrace? stackTrace, String? tag}) → void
Logs a message at the error level. The message is associated with an error and can optionally be associated with a stack trace.
info(String message, {String? tag}) → void
Logs a message at the info level.
log(BDLevel level, String message, {Object? error, StackTrace? stackTrace, bool? isFatal}) → void
Use this method to create log entries for user-defined levels. To record a message at a predefined level (e.g. BDLevel.info, BDLevel.warning) you can use their specialized methods instead (e.g. info, warning, etc).
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
removeHandler(BDLogHandler handler) bool
Removes a log handler from the logger. The handler will no longer be used to process log records.
success(String message, {String? tag}) → void
Logs a message at the success level.
toString() String
A string representation of this object.
inherited
warning(String message, {String? tag, dynamic error, bool? isFatal, StackTrace? stackTrace}) → void
Logs a message at the warning level. The message can optionally be associated with an error and a stack trace.

Operators

operator ==(Object other) bool
The equality operator.
inherited

Constants

defaultProcessingBatchSize → const int
The default number of log records that are processed at a time.