Message constructor

Message(
  1. String message,
  2. Severity severity,
  3. String? tag,
  4. List<StackTraceElement>? stackTrace,
  5. Error? error,
  6. String? function,
  7. String? fileName,
  8. int? lineNumber, [
  9. Json? json,
])

Implementation

Message(this.message,
        this.severity,
        this.tag,
        this.stackTrace,
        this.error,
        this.function,
        this.fileName,
        this.lineNumber,
        [Json? json]) : super(LogType.message, json) {
  if (fileName == null) {

    final stackTraceElement = StackTrace.current.toString();
    final line = stackTraceElement.split('\n')[3];
    final regex = RegExp(r'#\d+\s+(.+)\s+\((.+):(\d+):(\d+)\)');
    final match = regex.firstMatch(line);

    if (match != null) {
      function = match.group(1);
      fileName = match.group(2);
      lineNumber = int.parse(match.group(3)!);
      InnerLog().d('Function: $function FileName: $fileName LineNumber: $lineNumber');
    }

    if (tag == null || tag!.isEmpty) {
      // get the substring from the first character to the first dot.
      tag = fileName?.substring(0, fileName!.indexOf('.')) ?? '<unknown>';
    }
  }
}