logd_sqlite 0.1.3 copy "logd_sqlite: ^0.1.3" to clipboard
logd_sqlite: ^0.1.3 copied to clipboard

High-performance SQLite log sink for logd featuring WAL mode, prepared statements, atomic transaction batching, retention policies, and full-text search.

example/main.dart

// Copyright (c) 2026, Pooria Askari Moqaddam. All rights reserved.
// Use of this source code is governed by a BSD-3-Clause license that can be
// found in the LICENSE file.

import 'package:logd/logd.dart';
import 'package:logd_sqlite/logd_sqlite.dart';

void main() async {
  // 1. Initialize SQLite persistence sink
  final sqliteSink = SqliteSink(
    dbPath: 'example_logs.db',
    maxEntries: 1000,
    maxAge: const Duration(days: 7),
    batchSize: 20,
    flushInterval: const Duration(seconds: 1),
    walMode: true,
  );

  // 2. Configure logd pipeline with SqliteSink
  Logger.configure(
    'global',
    handlers: [
      Handler(
        formatter: const PlainFormatter(),
        sink: sqliteSink,
      ),
    ],
  );

  // 3. Emit structured logs
  Logger.get('app.payment')
    ..info(
      'Processing payment',
      context: const {'transactionId': 'TX-9042', 'amount': 250.00},
    )
    ..warning(
      'Payment latency spike',
      context: const {'durationMs': 1250},
    );

  // Flush buffer to SQLite database
  await sqliteSink.flush();

  // 4. Query & Filter logs
  final warningLogs = sqliteSink.queryLogs(
    minLevel: LogLevel.warning,
    search: 'Payment',
    limit: 10,
  );
  print('Found ${warningLogs.length} warning logs.');

  // 5. Inspect database stats & cleanup
  final counts = sqliteSink.fetchLevelCounts();
  print('Level breakdown: $counts');

  await sqliteSink.dispose();
}
1
likes
160
points
236
downloads

Documentation

Documentation
API reference

Publisher

unverified uploader

Weekly Downloads

High-performance SQLite log sink for logd featuring WAL mode, prepared statements, atomic transaction batching, retention policies, and full-text search.

Repository (GitHub)
View/report issues
Contributing

Topics

#logging #sqlite #persistence #database #structured-logging

License

BSD-3-Clause (license)

Dependencies

logd, meta, sqlite3

More

Packages that depend on logd_sqlite