Skip to content

Commit

Permalink
Log | LogLevel | fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
a-givertzman committed Dec 11, 2024
1 parent 5851c3c commit d60ba95
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 25 deletions.
16 changes: 8 additions & 8 deletions lib/src/core/log/console_colors.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ class ConsoleColors {
static const fgGray = '\x1b[90m';
//
// Bold
static const fgBoldBlack = '\x1b[1;30m'; // Black
static const fgBoldRed = '\x1b[1;31m'; // Red
static const fgBoldGreen = '\x1b[1;32m'; // Green
static const fgBoldYellow = '\x1b[1;33m'; // Yellow
static const fgBoldBlue = '\x1b[1;34m'; // Blue
static const fgBoldPurple = '\x1b[1;35m'; // Purple
static const fgBoldCyan = '\x1b[1;36m'; // Cyan
static const fgBoldWhite = '\x1b[1;37m'; // White
static const fgBoldBlack = '\x1b[1;30m'; // Bold Black
static const fgBoldRed = '\x1b[1;31m'; // Bold Red
static const fgBoldGreen = '\x1b[1;32m'; // Bold Green
static const fgBoldYellow = '\x1b[1;33m'; // Bold Yellow
static const fgBoldBlue = '\x1b[1;34m'; // Bold Blue
static const fgBoldPurple = '\x1b[1;35m'; // Bold Purple
static const fgBoldCyan = '\x1b[1;36m'; // Bold Cyan
static const fgBoldWhite = '\x1b[1;37m'; // Bold White
//
// Regular background
static const bgBlack = '\x1b[40m';
Expand Down
45 changes: 28 additions & 17 deletions lib/src/core/log/log.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,34 @@ class Log {
hierarchicalLoggingEnabled = true;
Logger.root.level = level ?? LogLevel.all; // defaults to Level.INFO
Logger.root.onRecord.listen((record) {
if (record.level == LogLevel.all) {
_logColored(ConsoleColors.fgGray, '${record.time} | ${record.level.name} | ${record.loggerName}${record.message}');
} else if (record.level == LogLevel.trace) {
_logColored(ConsoleColors.fgBoldCyan, '${record.time} | ${record.level.name} | ${record.loggerName}${record.message}');
} else if (record.level == LogLevel.debug) {
_logColored(ConsoleColors.fgBlue, '${record.time} | ${record.level.name} | ${record.loggerName}${record.message}');
} else if (record.level == LogLevel.config) {
_logColored(ConsoleColors.fgPurple, '${record.time} | ${record.level.name} | ${record.loggerName}${record.message}');
} else if (record.level == LogLevel.info) {
_logColored(ConsoleColors.fgGray, '${record.time} | ${record.level.name} | ${record.loggerName}${record.message}');
} else if (record.level == LogLevel.warning) {
_logColored(ConsoleColors.fgYellow, '${record.time} | ${record.level.name} | ${record.loggerName}${record.message}');
} else if (record.level == LogLevel.error) {
_logColored(ConsoleColors.fgRed, '${record.time} | ${record.level.name} | ${record.loggerName}${record.message}');
} else {
_logColored(ConsoleColors.fgGray, '${record.time} | ${record.level.name} | ${record.loggerName}${record.message}');
}
final color = switch (record.level) {
LogLevel.all => ConsoleColors.fgGray,
LogLevel.trace => ConsoleColors.fgBoldCyan,
LogLevel.debug => ConsoleColors.fgBlue,
LogLevel.config => ConsoleColors.fgPurple,
LogLevel.info => ConsoleColors.fgGray,
LogLevel.warning => ConsoleColors.fgYellow,
LogLevel.error => ConsoleColors.fgRed,
_ => ConsoleColors.fgGray,
};
_logColored(color, '${record.time} | ${record.level.name} | ${record.loggerName}${record.message}');
// if (record.level == LogLevel.all) {
// _logColored(ConsoleColors.fgGray, '${record.time} | ${record.level.name} | ${record.loggerName}${record.message}');
// } else if (record.level == LogLevel.trace) {
// _logColored(ConsoleColors.fgBoldCyan, '${record.time} | ${record.level.name} | ${record.loggerName}${record.message}');
// } else if (record.level == LogLevel.debug) {
// _logColored(ConsoleColors.fgBlue, '${record.time} | ${record.level.name} | ${record.loggerName}${record.message}');
// } else if (record.level == LogLevel.config) {
// _logColored(ConsoleColors.fgPurple, '${record.time} | ${record.level.name} | ${record.loggerName}${record.message}');
// } else if (record.level == LogLevel.info) {
// _logColored(ConsoleColors.fgGray, '${record.time} | ${record.level.name} | ${record.loggerName}${record.message}');
// } else if (record.level == LogLevel.warning) {
// _logColored(ConsoleColors.fgYellow, '${record.time} | ${record.level.name} | ${record.loggerName}${record.message}');
// } else if (record.level == LogLevel.error) {
// _logColored(ConsoleColors.fgRed, '${record.time} | ${record.level.name} | ${record.loggerName}${record.message}');
// } else {
// _logColored(ConsoleColors.fgGray, '${record.time} | ${record.level.name} | ${record.loggerName}${record.message}');
// }
});
}
///
Expand Down

0 comments on commit d60ba95

Please sign in to comment.