eventLog static method

Future<void> eventLog({
  1. String className = "",
  2. String methodName = "",
  3. String url = "",
  4. String postRequest = "",
  5. String postResponse = "",
  6. String appLog = "",
})

Implementation

static Future<void> eventLog({
  String className = "",
  String methodName = "",
  String url = "",
  String postRequest = "",
  String postResponse = "",
  String appLog = "",
}) async {
  try {
    final String filePath = await getLogFilePath();
    final File file = File(filePath);
    final String classN = className.isNotEmpty
        ? "[ ${LogConstants.className} $className ] |"
        : "";
    final String methodN = methodName.isNotEmpty
        ? "[ ${LogConstants.methodName} $methodName ] |"
        : "";
    final String urlEnd =
        url.isNotEmpty ? "[ ${LogConstants.apiUrl} $url} ] |" : "";
    final String pRequest = postRequest.isNotEmpty
        ? "[ ${LogConstants.apiRequest} $postRequest ] |"
        : "";
    final String log =
        appLog.isNotEmpty ? "[ ${LogConstants.appLog} $appLog ]" : "";

    String finalLog =
        "${DateTime.now().toLocal()} ${classN.isNotEmpty ? classN : ""} ${methodN.isNotEmpty ? methodN : ""} ${urlEnd.isNotEmpty ? urlEnd : ""} ${pRequest.isNotEmpty ? pRequest : ""} ${postResponse.isNotEmpty ? postResponse : ""} ${log.isNotEmpty ? log : ""} \n";

    file.writeAsStringSync(
      finalLog,
      mode: FileMode.append,
    );
  } catch (e) {
    if (kDebugMode) {
      print(e);
    }
  }
}