setLog method

Future<LogStatus> setLog({
  1. required String errorTitle,
  2. required String errorMessage,
  3. required LogLevel level,
})

Implementation

Future<LogStatus> setLog(
    {required String errorTitle,
    required String errorMessage,
    required LogLevel level}) async {
  try {
    String logEntry =
        '${DateTime.now()};${level.toString().split('.').last.toUpperCase()};$errorTitle;$errorMessage\n';

    await logFile?.writeAsString(logEntry, mode: FileMode.append);
    return LogStatus(status: true, msg: "Log Saved Successfully");
  } catch (e) {
    return LogStatus(status: false, msg: e.toString());
  }
}