templateBox method

void templateBox({
  1. required LoggerTypeState type,
  2. LoggerChannelState? channel,
  3. required String message,
  4. required StackTrace stack,
  5. List<String>? tags,
})

Creates a log box with a header, body message, and footer.

This function takes a required type parameter that defines the type of log message (debug, info, warning, or error), a channel parameter that specifies the channel on which the message is sent (if applicable), a required message parameter that contains the text of the message, a stack parameter that contains the stack trace for the message, and an optional tags parameter that contains tags to be included in the log message.

If tags is not null and not empty, each tag is converted to title case and added to the beginning of the log message in square brackets. The message is then appended after the tags. If tags is null or empty, the message parameter is used as the log message without any tags.

The message parameter is checked for its length, and if it exceeds the maximum character count, it is split into multiple lines while retaining whole words.

The log box consists of a header, the message body (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.info;
final channel = LoggerChannelState.http;
final message = 'HTTP response received';
final stack = StackTrace.current;
final tags = ['networking', 'response'];

templateBox(type: type, channel: channel, message: message, stack: stack, tags: tags);

Implementation

void templateBox(
    {required LoggerTypeState type,
    LoggerChannelState? channel,
    required String message,
    required StackTrace stack,
    List<String>? tags}) {
  _boxHeader(type: type, channel: channel);

  String bodyMessage = "";

  if (tags != null && tags.isNotEmpty) {
    List<String> convertInTagFormat = tags
        .map((tag) =>
            "[${tag[0].toUpperCase()}${tag.substring(1).toLowerCase()}]")
        .toList();
    for (var tag in convertInTagFormat) {
      bodyMessage += tag;
    }
    bodyMessage += " - $message";
  } else {
    bodyMessage = message;
  }

  List<String> lengthSplitterObject =
      splitObjectIfTooLong(object: bodyMessage);
  _templateTextMultiLines(textList: lengthSplitterObject);

  _boxFooter(stack: stack);
}