Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions .github/workflows/talker_drift_logger.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: talker_drift_logger

on:
push:
paths:
- "packages/talker_drift_logger/**"
- ".github/workflows/talker_drift_logger.yaml"
pull_request:
paths:
- "packages/talker_drift_logger/**"
- ".github/workflows/talker_drift_logger.yaml"
permissions:
contents: read

jobs:
test:
uses: ./.github/workflows/test.yaml
with:
package: talker_drift_logger
sdk: dart
chrome: false
48 changes: 47 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ Talker is designed for any level of customization. <br>
| [talker_chopper_logger](https://github.com/Frezyx/talker/tree/master/packages/talker_chopper_logger) | [![Pub](https://img.shields.io/pub/v/talker_chopper_logger.svg?style=flat-square)](https://pub.dev/packages/talker_chopper_logger) | Best logger for [Chopper](https://pub.dev/packages/chopper) http calls |
| [talker_http_logger](https://github.com/Frezyx/talker/tree/master/packages/talker_http_logger) | [![Pub](https://img.shields.io/pub/v/talker_http_logger.svg?style=flat-square)](https://pub.dev/packages/talker_http_logger) | Best logger for [http](https://pub.dev/packages/http) package |
| [talker_grpc_logger](https://github.com/Frezyx/talker/tree/master/packages/talker_grpc_logger) | [![Pub](https://img.shields.io/pub/v/talker_grpc_logger.svg?style=flat-square)](https://pub.dev/packages/talker_grpc_logger) | Best logger for [grpc](https://pub.dev/packages/grpc) package |
| [talker_drift_logger](https://github.com/Frezyx/talker/tree/master/packages/talker_drift_logger) | [![Pub](https://img.shields.io/pub/v/talker_drift_logger.svg?style=flat-square)](https://pub.dev/packages/talker_drift_logger) | Best logger for [Drift](https://pub.dev/packages/drift) database |

## Table of contents

Expand Down Expand Up @@ -128,7 +129,52 @@ Talker is designed for any level of customization. <br>
- [Getting Started](#getting-started-4)
- [Using with Talker](#using-with-talker-3)
- [Token obfuscation](#token-obfuscation)
- [Crashlytics integration](#crashlytics-integration)

## Talker Drift Logger

Lightweight, simple and pretty solution for logging Drift database operations using [Drift](https://pub.dev/packages/drift).

This is how SQL statements and results will look in the console with Talker formatting and colors.

### Getting Started
Follow these steps to use this package

### Add dependency
```yaml
dependencies:
talker_drift_logger: ^5.0.0
```

### Usage
Attach an interceptor to Drift executor via `interceptWith`:

```dart
import 'package:drift/drift.dart';
import 'package:drift/native.dart';
import 'package:talker_drift_logger/talker_drift_logger.dart';

final executor = NativeDatabase.memory().interceptWith(
TalkerDriftLogger(
settings: const TalkerDriftLoggerSettings(
printArgs: true,
printResults: true,
),
),
);
```

### Using with Talker
You can add your Talker instance for `TalkerDriftLogger` if your application already uses Talker.
In this case, all logs and errors will fall into your unified tracking system and appear in Talker UI filters.

```dart
final talker = Talker();
final executor = NativeDatabase('app.db').interceptWith(
TalkerDriftLogger(talker: talker),
);
```

## Crashlytics integration
- [Features list](#features-list)
- [Coverage](#coverage)
- [Additional information](#additional-information)
Expand Down
14 changes: 14 additions & 0 deletions packages/talker/lib/src/settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ final _defaultTitles = {
TalkerKey.riverpodDispose: 'riverpod-dispose',
TalkerKey.riverpodFail: 'riverpod-fail',

/// Drift section
TalkerKey.driftError: 'drift-error',
TalkerKey.driftQuery: 'drift-query',
TalkerKey.driftResult: 'drift-result',
TalkerKey.driftTransaction: 'drift-transaction',
TalkerKey.driftBatch: 'drift-batch',

/// Flutter section
TalkerKey.route: 'route',
};
Expand Down Expand Up @@ -58,6 +65,13 @@ final _defaultColors = {
TalkerKey.riverpodDispose: AnsiPen()..xterm(198),
TalkerKey.riverpodFail: AnsiPen()..red(),

/// Drift section
TalkerKey.driftError: AnsiPen()..red(),
TalkerKey.driftQuery: AnsiPen()..xterm(219),
TalkerKey.driftResult: AnsiPen()..xterm(46),
TalkerKey.driftTransaction: AnsiPen()..xterm(135),
TalkerKey.driftBatch: AnsiPen()..xterm(49),

/// Flutter section
TalkerKey.route: AnsiPen()..xterm(135),
};
Expand Down
7 changes: 7 additions & 0 deletions packages/talker/lib/src/talker_key.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@ abstract class TalkerKey {
static const grpcResponse = 'grpc-response';
static const grpcError = 'grpc-error';

/// Drift section
static const driftQuery = 'drift-query';
static const driftResult = 'drift-result';
static const driftError = 'drift-error';
static const driftTransaction = 'drift-transaction';
static const driftBatch = 'drift-batch';

/// Flutter section
static const route = 'route';

Expand Down
31 changes: 31 additions & 0 deletions packages/talker_drift_logger/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Miscellaneous
*.class
*.log
*.pyc
*.swp
.DS_Store
.atom/
.buildlog/
.history
.svn/

# IntelliJ related
*.iml
*.ipr
*.iws
.idea/

# The .vscode folder contains launch configuration and tasks you configure in
# VS Code which you may wish to be included in version control, so this line
# is commented out by default.
#.vscode/

# Flutter/Dart/Pub related
# Libraries should not include pubspec.lock, per https://dart.dev/guides/libraries/private-files#pubspeclock.
/pubspec.lock
**/doc/api/
.dart_tool/
.packages
build/
.flutter-plugins
.flutter-plugins-dependencies
10 changes: 10 additions & 0 deletions packages/talker_drift_logger/.metadata
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# This file tracks properties of this Flutter project.
# Used by Flutter tool to assess capabilities and perform upgrades etc.
#
# This file should be version controlled and should not be manually edited.

version:
revision: ffccd96b62ee8cec7740dab303538c5fc26ac543
channel: stable

project_type: package
6 changes: 6 additions & 0 deletions packages/talker_drift_logger/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
## 5.0.0
- Initial release of `talker_drift_logger`
- Drift `QueryInterceptor` with query/result/error/transaction/batch logs
- Pretty JSON output, args/result printing with obfuscation and limits
- Customization via `TalkerDriftLoggerSettings`
- Tests and example
90 changes: 90 additions & 0 deletions packages/talker_drift_logger/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
# talker_drift_logger
Lightweight and customizable [Drift](https://pub.dev/packages/drift) SQL logger on [talker](https://pub.dev/packages/talker) base.<br>
[Talker](https://github.com/Frezyx/talker) - Advanced exception handling and logging for dart/flutter applications 🚀

<p>
<a href="https://github.com/Frezyx/talker"><img src="https://img.shields.io/github/stars/Frezyx/talker?style=social" alt="GitHub"></a>
<a href="https://codecov.io/gh/Frezyx/talker"><img src="https://codecov.io/gh/Frezyx/talker/branch/master/graph/badge.svg" alt="codecov"></a>
<a href="https://pub.dev/packages/talker_drift_logger"><img src="https://img.shields.io/pub/v/talker_drift_logger.svg" alt="Pub"></a>
<a href="https://opensource.org/licenses/MIT"><img src="https://img.shields.io/badge/license-MIT-blue.svg" alt="License: MIT"></a>
</p>

## Getting started

### Add dependency
```yaml
dependencies:
talker_drift_logger: ^5.0.0
```

### Usage
Attach `TalkerDriftLogger` via Drift interceptors and that's it:

```dart
import 'package:drift/drift.dart';
import 'package:drift/native.dart';
import 'package:talker_drift_logger/talker_drift_logger.dart';

final talker = Talker();

final executor = NativeDatabase.memory().interceptWith(
TalkerDriftLogger(
talker: talker,
settings: const TalkerDriftLoggerSettings(
printArgs: true,
printResults: true,
),
),
);

// If you're using a GeneratedDatabase subclass:
final db = MyDatabase(executor);
```

You can also wrap an existing `DatabaseConnection` or use `runWithInterceptor` for scoped logging.

## Settings

`TalkerDriftLoggerSettings` gives you full control:

- enabled (default: true)
- logLevel (default: LogLevel.debug)
- printArgs / printResults
- resultRowLimit / resultMaxChars
- printTransaction / printBatch
- obfuscateColumns (case-insensitive)
- obfuscatePatterns (Pattern-based masking)
- queryPen / resultPen / errorPen / transactionPen / batchPen
- statementFilter / errorFilter
- resultPrinter / argsPrinter

Example:
```dart
TalkerDriftLogger(
talker: talker,
settings: const TalkerDriftLoggerSettings(
printArgs: true,
printResults: true,
resultRowLimit: 50,
resultMaxChars: 2000,
obfuscateColumns: {'password', 'token'},
),
);
```

## Using with Talker
Provide your Talker instance if your app already uses Talker. In this case, all logs will go into your unified logging pipeline and UI (filters).

```dart
final talker = Talker();
final executor = NativeDatabase('app.db').interceptWith(TalkerDriftLogger(talker: talker));
```

## Notes

- Transactions (`begin`, `commit`, `rollback`) and batched statements are logged as well (configurable).
- This package prints pretty JSON, masks sensitive data, and limits result sizes to keep console clean.

## Additional information
The project is under development and ready for your pull-requests and issues 👍<br>
Thank you for support ❤️
16 changes: 16 additions & 0 deletions packages/talker_drift_logger/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# This file configures the static analysis results for your project (errors,
# warnings, and lints).
#
# This enables the 'recommended' set of lints from `package:lints`.
# The core lints are also what is used by pub.dev for scoring packages.

include: package:lints/recommended.yaml

# Uncomment to customize rules
# linter:
# rules:
# - always_use_package_imports

# analyzer:
# exclude:
# - test/**/goldens/**
39 changes: 39 additions & 0 deletions packages/talker_drift_logger/example/lib/main.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import 'package:drift/drift.dart';
import 'package:drift/native.dart';
import 'package:talker/talker.dart';
import 'package:talker_drift_logger/talker_drift_logger.dart';

// Run: dart run bin/main.dart
Future<void> main() async {
final talker = Talker();

final executor = NativeDatabase.memory().interceptWith(
TalkerDriftLogger(
talker: talker,
settings: const TalkerDriftLoggerSettings(
printArgs: true,
printResults: true,
),
),
);

final db = _DummyDb(executor);

await db.customStatement(
'CREATE TABLE users (id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, name TEXT);');
await db.customStatement("INSERT INTO users (name) VALUES ('Alice')");
await db.customStatement("INSERT INTO users (name) VALUES ('Bob')");

final rows = await db.customSelect('SELECT * FROM users').get();
talker.info('Selected ${rows.length} users');
}

class _DummyDb extends GeneratedDatabase {
_DummyDb(QueryExecutor e) : super(e);
@override
int get schemaVersion => 1;
@override
Iterable<TableInfo<Table, Object?>> get allTables => const [];
@override
List<DatabaseSchemaEntity> get allSchemaEntities => const [];
}
Loading