TwkLogger class

Singleton logger for the Tawakkalna SDK.

Provides centralized logging with level filtering, memory management, and listener support for log streaming.

Features:

  • Automatic memory management (keeps last 1000 logs)
  • Enable/disable logging dynamically
  • Filter logs by level
  • Stream logs to listeners
  • Console output in debug mode

Example:

final logger = TwkLogger();
logger.info('User logged in');
logger.error('Failed to fetch data', data: {'error': 'Network timeout'});

// Add a listener
logger.addListener((entry) {
  print('New log: ${entry.message}');
});

// Disable logging
logger.setEnabled(false);

Constructors

TwkLogger()
factory

Properties

hashCode → int
The hash code for this object.
no setterinherited
isEnabled → bool
Returns whether logging is currently enabled
no setter
logs → List<LogEntry>
Returns all logged entries.
no setter
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited

Methods

addListener(void listener(LogEntry)) → void
Adds a listener that will be called for each new log entry.
clear() → void
Clears all logged entries from memory.
debug(String message, {String? source, dynamic data}) → void
Logs a debug-level message.
error(String message, {String? source, dynamic data}) → void
Logs an error-level message.
getLogsByLevel(LogLevel level) → List<LogEntry>
Returns logs filtered by a specific level.
getRecentLogs(int count) → List<LogEntry>
Returns the most recent logs.
getStatistics() → Map<String, int>
Returns statistics about logged entries.
info(String message, {String? source, dynamic data}) → void
Logs an info-level message.
log(String message, {LogLevel level = LogLevel.info, String? source, dynamic data}) → void
Logs a message with specified level and optional metadata.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
removeListener(void listener(LogEntry)) → void
Removes a previously added listener.
setEnabled(bool enabled) → void
Enables or disables logging.
toString() → String
A string representation of this object.
inherited
warning(String message, {String? source, dynamic data}) → void
Logs a warning-level message.

Operators

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