configureLogger function
void
configureLogger()
Implementation
void configureLogger() {
Logger.root.level =
Level.ALL; // Set the log level (You can adjust this as needed)
Logger.root.onRecord.listen((record) {
// Define ANSI escape code sequences for different log levels and colors
final Map<Level, String> colorMap = {
Level.INFO: '\x1B[32m', // Green for INFO
Level.WARNING: '\x1B[33m', // Yellow for WARNING
Level.SEVERE: '\x1B[31m', // Red for SEVERE
Level.SHOUT: '\x1B[35m', // Magenta for SHOUT (if used)
Level.CONFIG: '\x1B[36m', // Cyan for CONFIG (if used)
// Add more colors for other log levels if needed
};
// Reset color at the end of the log message
const String colorReset = '\x1B[0m';
// Get the color code for the log level
final String colorCode = colorMap[record.level] ?? '';
// You can customize the log message format here, including color
debugPrint(
'$colorCode${record.level.name}: ${record.time}: ${record.message}$colorReset');
});
}