log method

void log(
  1. String message, {
  2. LogType type = LogType.info,
})

Logs a message to the console if debug mode is enabled.

The message parameter is the log message to be printed. The optional type parameter specifies the type of log message and defaults to LogType.info.

Implementation

void log(String message, {LogType type = LogType.info}) {
  if (debugMode) {
    String colorCode;
    switch (type) {
      case LogType.init:
        colorCode = '\x1B[32m'; // Green
        break;
      case LogType.error:
        colorCode = '\x1B[31m'; // Red
        break;
      case LogType.info:
      default:
        colorCode = '\x1B[34m'; // Blue
        break;
    }
    // Reset color
    String resetCode = '\x1B[0m';
    print('$colorCode$message$resetCode');
  }
}