makeObjectGroup method

  1. @override
void makeObjectGroup(
  1. String groupName,
  2. LogRecord logRecord
)
override

groupName is for example GROUP_OBJECT

Implementation

@override
void makeObjectGroup(final String groupName, final LogRecord logRecord) {
  void makeGroupWithString(
      final String groupName, final String objectAsString) {
    window.console.groupCollapsed(groupName);
    window.console.log(objectAsString);
    window.console.groupEnd();
  }

  if (logRecord.error != null) {
    final Object? error = logRecord.error;

    final String groupNameWithType = "$groupName (${error.runtimeType})";
    if (error is Map || error is List) {
      try {
        makeGroupWithString(groupNameWithType, prettyPrintJson(error));
      } on FormatException {
        makeGroupWithString(groupNameWithType, error.toString());
      }
    } else {
      try {
        final decoded = JSON.decode(error.toString());
        makeGroupWithString(groupNameWithType, prettyPrintJson(decoded));
      } on Exception {
        makeGroupWithString(groupNameWithType, error.toString());
      }
    }
  }
}