logMessage static method
void
logMessage(})
Logs a message with the specified text
and optional name
.
This method handles logging of 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:
text
(String
): The message to log.name
(String?
): The name of the file to include in 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 white.fileNameColor
(LogColors?
): The color to use for the file name part of the log message. If not provided, the default color is white.
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 and file name with specified or default colors.
Example:
AppLogs.logMessage(
"This is a log message.",
name: "example.dart",
msgColor: LogColors.green,
textColor: LogColors.blue,
fileNameColor: LogColors.yellow,
);
Implementation
static void logMessage(
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}] "
"${colorTo(msgColor, LogColors.white)} $text ${LogColors.reset.value}");
}
}