writeLog method
- dynamic msg,
- {StackTrace st}
Write log
msg
can be in String, Error and LogMsg
All messages will eventually convert to LogMsg
Implementation
Future<bool> writeLog(
dynamic msg, {
StackTrace st,
}) async {
LogMsg logMsg;
ConnectivityResult connectivityResult =
await (Connectivity().checkConnectivity());
if (msg is String)
logMsg = LogMsg(
'String Message',
DateTime.now(),
msg,
networkState: connectivityResult.toString(),
stackTrace: StackTrace.current,
);
if (msg is Error)
logMsg = LogMsg(
'Error',
DateTime.now(),
msg.toString(),
networkState: connectivityResult.toString(),
stackTrace: msg.stackTrace,
);
if (msg is LogMsg) {
logMsg = LogMsg(
msg.tag,
msg.datetime,
msg.message,
networkState: connectivityResult.toString(),
stackTrace: msg.stackTrace,
otherInfo: msg.otherInfo,
);
}
if (_localLog) {
String formattedLog = _formatLog(logMsg);
await writeFile(_path, "$_logFileName.txt", formattedLog);
}
if (_otherLog && _otherLogConfig != null) {
_otherLogConfig.logFnc(logMsg);
}
return true;
}