Skip to content

Commit

Permalink
Log | LogLevel | trace
Browse files Browse the repository at this point in the history
  • Loading branch information
a-givertzman committed Dec 11, 2024
1 parent b6fab34 commit 760c265
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
9 changes: 9 additions & 0 deletions lib/src/core/log/log.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ class Log {
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.fgCyan, '${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) {
Expand All @@ -40,6 +42,13 @@ class Log {
log(true, '$color$message${ConsoleColors.reset}');
}
///
/// Log message at level [LogLevel.trace].
///
/// See [log] for information on how non-String [message] arguments are
/// handled.
void trace(Object? message, [Object? error, StackTrace? stackTrace]) =>
Logger(_name).log(LogLevel.trace, message, error, stackTrace);
///
/// Log message at level [LogLevel.debug].
///
/// See [log] for information on how non-String [message] arguments are
Expand Down
6 changes: 5 additions & 1 deletion lib/src/core/log/log_level.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import 'package:logging/logging.dart';
/// follows (in descending order):
/// - [LogLevel.off],
/// - [LogLevel.error], [LogLevel.warning],
/// - [LogLevel.info], [LogLevel.config], [LogLevel.debug],
/// - [LogLevel.info], [LogLevel.config], [LogLevel.debug], [LogLevel.trace],
/// - [LogLevel.all].
///
/// We recommend using one of the predefined logging levels. If you define your
Expand All @@ -17,6 +17,9 @@ class LogLevel extends Level {
/// Special key to turn on logging for all levels ([value] = 0).
static const LogLevel all = LogLevel('ALL', 0);
///
/// Key for detailed tracing information ([value] = 400).
static const LogLevel trace = LogLevel('TRACE', 400);// Level.FINER;
///
/// Key for tracing information ([value] = 500).
static const LogLevel debug = LogLevel('DEBUG', 500);// Level.FINE;
///
Expand Down Expand Up @@ -61,6 +64,7 @@ class LogLevel extends Level {
///
static const List<LogLevel> levels = [
all,
trace,
debug,
config,
info,
Expand Down

0 comments on commit 760c265

Please sign in to comment.