logWarning static method

void logWarning(
  1. String? text, {
  2. String? name,
  3. String? error,
  4. StackTrace? stackTrace,
  5. LogColors? msgColor,
  6. LogColors? textColor,
  7. LogColors? fileNameColor,
  8. LogColors? warningColor,
  9. LogColors? stackTraceColor,
})

Logs a warning message with the specified text, name, error, and stackTrace.

This method handles logging of warning messages with optional color formatting for the text, warning message, file name, and stack trace. It respects the printHandle flag and only logs messages if certain conditions are met.

Parameters:

  • text (String): The warning message or additional information to log.
  • name (String?): The name of the file to include in the log message. This parameter is optional.
  • error (String?): The warning error message to log. This parameter is optional.
  • stackTrace (StackTrace?): The stack trace associated with the warning. This parameter is optional.
  • msgColor (LogColors?): The color to use for the main log message. If not provided, the default color is magenta.
  • textColor (LogColors?): The color to use for the text part of the log message. If not provided, the default color is yellow.
  • fileNameColor (LogColors?): The color to use for the file name part of the log message. If not provided, the default color is blue.
  • warningColor (LogColors?): The color to use for the warning message part of the log message. If not provided, the default color is yellow.
  • stackTraceColor (LogColors?): The color to use for the stack trace part of the log message. If not provided, the default color is yellow.

Returns:

  • (void): This method does not return a value.

Notes:

  • If printHandle is true, no logging will occur.
  • If AppLogs.screens is not empty and name is not included in AppLogs.screens, logging will not occur.
  • The method will print the log message, warning message, file name, and stack trace with specified or default colors.

Example:

AppLogs.logWarning(
  "This is a warning message.",
  name: "example.dart",
  error: "Warning occurred.",
  stackTrace: StackTrace.current,
  msgColor: LogColors.orange,
  textColor: LogColors.blue,
  fileNameColor: LogColors.green,
  warningColor: LogColors.yellow,
  stackTraceColor: LogColors.cyan,
);

Implementation

static void logWarning(
  String? text, {
  String? name,
  String? error,
  StackTrace? stackTrace,
  LogColors? msgColor,
  LogColors? textColor,
  LogColors? fileNameColor,
  LogColors? warningColor,
  LogColors? stackTraceColor,
}) {
  if (printHandle) {
    return;
  }
  if (AppLogs.screens.isNotEmpty) {
    if (!AppLogs.screens.contains(name)) {
      return;
    }
  }
  if (kDebugMode) {
    print(
      "[${msgColor?.value ?? (name != null ? (fileNameColor?.value ?? LogColors.magenta.value) : LogColors.magenta.value)} ${name ?? 'LOG MESSAGE'} ${LogColors.reset.value}] ${textColor?.value ?? (name != null ? LogColors.white.value : LogColors.yellow.value)} $text ${LogColors.reset.value}",
    );
    print(
      "[${msgColor?.value ?? LogColors.magenta.value} LOG WARNING MESSAGE ${LogColors.reset.value}] ${warningColor?.value ?? LogColors.yellow.value} ${error.toString()} ${LogColors.reset.value}",
    );
    print(
      "[${msgColor?.value ?? LogColors.magenta.value} LOG STACKTRACE MESSAGE ${LogColors.reset.value}] ${stackTraceColor?.value ?? LogColors.yellow.value} ${stackTrace.toString()} ${LogColors.reset.value}",
    );
  }
}