logSuccess static method

void logSuccess(
  1. String? text, {
  2. String? name,
  3. LogColors? msgColor,
  4. LogColors? textColor,
  5. LogColors? fileNameColor,
})

Logs a success message with the specified text and name.

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

Parameters:

  • name (String?): The name of the file to include in the log message. This parameter is optional.
  • text (String?): The text of the log message. 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 green.
  • fileNameColor (LogColors?): The color to use for the file name part of the log message. If not provided, the default color is blue.

The method will:

  • Return immediately if printHandle is true, meaning no logging will occur.
  • Check if AppLogs.screens is not empty and if name is not included in AppLogs.screens, it will return without logging.
  • Print the log message and file name with specified or default colors.

Example:

AppLogs.logSuccess(
  name: "example.dart",
  text: "Operation completed successfully.",
  msgColor: LogColors.magenta,
  textColor: LogColors.green,
  fileNameColor: LogColors.blue,
);

This will print:

[35 LOG MESSAGE 0] 32 Operation completed successfully. 0
[35 LOG FILE NAME MESSAGE 0] 34 example.dart 0

Where 35 represents the color code for magenta, 32 for green, 34 for blue, and 0 for reset.

Notes:

  • The LogColors enum should be predefined with appropriate color codes for use in log messages.
  • The printHandle variable should be a boolean value indicating whether to handle print operations.
  • The AppLogs.screens should be a collection (e.g., a list) that may contain specific file names to be included in the logs.

Implementation

static void logSuccess(
  String? text, {
  String? name,
  LogColors? msgColor,
  LogColors? textColor,
  LogColors? fileNameColor,
}) {
  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.green.value)} $text ${LogColors.reset.value}",
    );
  }
}