templateDebug method

void templateDebug({
  1. required LoggerTypeState type,
  2. LoggerChannelState? channel,
  3. String? message,
  4. required dynamic object,
  5. required StackTrace stack,
})

Creates a log box with debug information, including the type and value of an object, and a message (if provided).

This function takes a required type parameter that specifies the type of debug information, a channel parameter that specifies the channel on which the message is sent (if applicable), an optional message parameter that contains the text of the message, a required object parameter that is the object whose type and value will be logged, and a stack parameter that contains the stack trace for the debug message.

If the message parameter is not null, it is added to the log box with a "Message:" label. The object parameter is then checked for its type and value, and both are added to the log box with a "Type:" and "Value:" label respectively. If the value of the object parameter is too long to fit in a single line, it is split into multiple lines while retaining whole words.

The log box consists of a header, the debug information (possibly spanning multiple lines), and a footer that contains the filename and line number of the code that generated the log.

Example:

final type = LoggerTypeState.debug;
final channel = LoggerChannelState.database;
final message = 'Failed to open database';
final object = DatabaseException('Failed to open database');
final stack = StackTrace.current;

templateDebug(type: type, channel: channel, message: message, object: object, stack: stack);

Implementation

void templateDebug(
    {required LoggerTypeState type,
    LoggerChannelState? channel,
    String? message,
    required dynamic object,
    required StackTrace stack}) {
  _boxHeader(type: type, channel: channel);

  if (message != null) {
    List<String> lengthSplitterObject = splitObjectIfTooLong(
        object: message.toString(), subMessage: "Message: ");
    _templateTextMultiLines(
        textList: lengthSplitterObject, subMessage: "Message: ");
  }
  List<String> lengthSplitterObject = splitObjectIfTooLong(
      object: object.runtimeType.toString(), subMessage: "Type: ");
  _templateTextMultiLines(
      textList: lengthSplitterObject, subMessage: "Type: ");

  List<String> lineSplitterObject = _splitObjectInMultiLines(object: object);
  if (lineSplitterObject.length > 1) {
    debugPrint(_lineText(
      primaryMessage: "Value: ",
    ));
    for (var i = 0; i < lineSplitterObject.length; i++) {
      List<String> lengthSplitterObject =
          splitObjectIfTooLong(object: lineSplitterObject[i]);
      _templateTextMultiLines(textList: lengthSplitterObject);
    }
  } else {
    _templateTextMultiLines(
        textList: lineSplitterObject, subMessage: "Value: ");
  }

  _boxFooter(stack: stack);
}