11import 'dart:convert' ;
2- import 'package:logger/logger.dart' ;
32import 'package:path/path.dart' ;
43import 'package:readeck_app/domain/models/daily_read_history/daily_read_history.dart' ;
4+ import 'package:readeck_app/main.dart' ;
55import 'package:result_dart/result_dart.dart' ;
66import 'package:sqflite/sqflite.dart' ;
77import 'package:sqflite_common/sqflite_logger.dart' ;
@@ -17,7 +17,6 @@ class DatabaseService {
1717 static const _kColumnBookmarkIds = 'bookmark_ids' ;
1818
1919 Database ? _database;
20- final _log = Logger ();
2120
2221 bool isOpen () {
2322 return _database? .isOpen ?? false ;
@@ -35,9 +34,9 @@ class DatabaseService {
3534 try {
3635 final result = await db.rawQuery ('SELECT sqlite_version()' );
3736 final version = result.first.values.first;
38- _log .i ('Current SQLite version: $version ' );
37+ appLogger .i ('Current SQLite version: $version ' );
3938 } catch (e) {
40- _log .e ('Failed to get SQLite version' , error: e);
39+ appLogger .e ('Failed to get SQLite version' , error: e);
4140 }
4241 return db.execute (
4342 '''CREATE TABLE $_kTableDailyReadHistory (
@@ -60,15 +59,17 @@ class DatabaseService {
6059 try {
6160 final id = await _database! .insert (_kTableDailyReadHistory,
6261 {_kColumnBookmarkIds: jsonEncode (bookmarkIds)});
63- _log. d (
62+ appLogger. i (
6463 "Inserted daily read history with id: $id . bookmarkIds: $bookmarkIds " );
6564 return Success (id);
6665 } on Exception catch (e) {
67- _log.e ("Failed to insert daily read history. bookmarkIds: $bookmarkIds " ,
66+ appLogger.e (
67+ "Failed to insert daily read history. bookmarkIds: $bookmarkIds " ,
6868 error: e);
6969 return Failure (e);
7070 } catch (e) {
71- _log.e ("Failed to insert daily read history. bookmarkIds: $bookmarkIds " ,
71+ appLogger.e (
72+ "Failed to insert daily read history. bookmarkIds: $bookmarkIds " ,
7273 error: e);
7374 return Failure (Exception (e));
7475 }
@@ -86,13 +87,13 @@ class DatabaseService {
8687 where: '$_kColumnId = ?' ,
8788 whereArgs: [obj.id],
8889 );
89- _log. d ("Updated daily read history with id: ${obj .id }. data: $obj " );
90+ appLogger. i ("Updated daily read history with id: ${obj .id }. data: $obj " );
9091 return Success (count);
9192 } on Exception catch (e) {
92- _log .e ("Failed to update daily read history. data: $obj " , error: e);
93+ appLogger .e ("Failed to update daily read history. data: $obj " , error: e);
9394 return Failure (e);
9495 } catch (e) {
95- _log .e ("Failed to update daily read history. data: $obj " , error: e);
96+ appLogger .e ("Failed to update daily read history. data: $obj " , error: e);
9697 return Failure (Exception (e));
9798 }
9899 }
@@ -124,17 +125,17 @@ class DatabaseService {
124125 limit: limit,
125126 offset: offset,
126127 );
127- _log. d ("Retrieved ${maps .length } daily read histories. data: $maps " );
128+ appLogger. i ("Retrieved ${maps .length } daily read histories. data: $maps " );
128129 final List <DailyReadHistory > histories = [];
129130 for (final map in maps) {
130131 histories.add (DailyReadHistory .fromJson (map));
131132 }
132133 return Success (histories);
133134 } on Exception catch (e) {
134- _log .e ("Failed to get daily read histories" , error: e);
135+ appLogger .e ("Failed to get daily read histories" , error: e);
135136 return Failure (e);
136137 } catch (e) {
137- _log .e ("Failed to get daily read histories" , error: e);
138+ appLogger .e ("Failed to get daily read histories" , error: e);
138139 return Failure (Exception (e));
139140 }
140141 }
@@ -148,13 +149,13 @@ class DatabaseService {
148149 try {
149150 // 清空每日阅读历史表
150151 await _database! .delete (_kTableDailyReadHistory);
151- _log .i ("Cleared all data from database" );
152+ appLogger .i ("Cleared all data from database" );
152153 return const Success (unit);
153154 } on Exception catch (e) {
154- _log .e ("Failed to clear all data from database" , error: e);
155+ appLogger .e ("Failed to clear all data from database" , error: e);
155156 return Failure (e);
156157 } catch (e) {
157- _log .e ("Failed to clear all data from database" , error: e);
158+ appLogger .e ("Failed to clear all data from database" , error: e);
158159 return Failure (Exception (e));
159160 }
160161 }
0 commit comments