LocalLogStorage class

Handles persistent storage of log entries using Sembast

Why Sembast over SQLite?

  • Works on ALL platforms (including web!)
  • NoSQL structure perfect for our metadata-rich logs
  • No native dependencies to worry about
  • Great performance with automatic indexing

Constructors

LocalLogStorage.new()
Get the singleton instance
factory

Properties

database Future<Database>
Get database instance (lazy initialization) Why lazy? We don't want to open DB until we actually need it
no setter
hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

clearLogs({DateTime? olderThan, List<LogLevel>? levels, List<String>? categories}) Future<void>
Clear logs with optional filtering Sembast makes this clean with its filtering system
exportLogs({List<LogLevel>? levels, DateTime? startTime, DateTime? endTime}) Future<String>
Export logs to JSON Perfect for external analysis or backup
getDatabaseInfo() Future<Map<String, dynamic>>
Get database info Useful for debugging and monitoring
getLogStatistics() Future<LogStatistics>
Get statistics about logs Demonstrates Sembast's aggregation capabilities
getUniqueCategories() Future<List<String>>
Get unique values for filtering UI Why? Powers dropdown filters in DevTools extension
getUniqueSessions() Future<List<String>>
getUniqueTags() Future<List<String>>
insertLog(LogEntry entry) Future<void>
Insert a single log entry Why auto-increment key? Sembast handles unique IDs for us
insertLogs(List<LogEntry> entries) Future<void>
Batch insert multiple log entries Why batch? Much faster than individual inserts, especially on web
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
queryLogs({List<LogLevel>? levels, List<String>? categories, List<String>? tags, String? messagePattern, DateTime? startTime, DateTime? endTime, String? userId, String? sessionId, int limit = 1000, int offset = 0, bool ascending = false}) Future<List<LogEntry>>
Query logs with flexible filtering This is where Sembast really shines - flexible querying without SQL
toString() String
A string representation of this object.
inherited

Operators

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