This package helps you to log app messages.

Features

Use FionaLogger to log your app messages into different repositories. A repository could be a system console, a file, a table into a database, anything you want to define as a repository.

Getting started

This packages implements a simple repository to write the messages into the system console, but then you are able to define your custom repositories.

To know about the idea and the structure you can read this article: https://medium.com/nerd-for-tech/logger-for-flutter-how-to-log-your-messages-in-flutter-944df9be487c

Usage

You can find a complete example into the example directory.

You have to use the package GetIt to register the log and its repository. The package contains the repository to use the system console (LogInConsole).


GetIt.instance.registerFactory<LogDataRepository>(() => LogInConsole());
GetIt.instance.registerFactory<FionaLogger>(() => FionaLogger(level: Level.verbose));

Then you will be able to use it:


FionaLogger logger = GetIt.instance<FionaLogger>();

logger.d("a debug message");
logger.i("an info message");
logger.e("an error message");

Also you are able to define your owns repositories. For example, I have a project where I use this package and I created a LogDataRepository to use SQLite:


class LogDataSQLite implements LogDataRepository{

  SQLiteDatabase _sqlite = DependencyManager().get<SQLiteDatabase>();


  @override
  Future<void> clear() async {
    final Database db = await _sqlite.initializeDB();
    try {
      await db.delete(SQLiteScheme.logData_tableName);
    } catch (err) {

    }
  }

  @override
  Future<void> add(LogData logData) async {
    final Database db = await _sqlite.initializeDB();
    await db.insert(
        SQLiteScheme.logData_tableName, logData.toMap(),
        conflictAlgorithm: ConflictAlgorithm.replace);
  }

  @override
  Future<List<LogData>> getAll() async {
    final Database db = await _sqlite.initializeDB();
    final List<Map<String, Object?>> queryResult =
    await db.query(SQLiteScheme.logData_tableName, orderBy: 'datetime DESC');
    return queryResult.map((e) => LogData.fromMap(e)).toList();
  }
  

Then into my project startup settings, I inject that dependency for the data repository


GetIt.instance.registerLazySingleton<LogDataRepository>(() => LogDataSQLite());

Additional information

Libraries

fiona_logger