diff --git a/crates/nu-utils/standard_library/std.nu b/crates/nu-utils/standard_library/std.nu index 0b21cf39fa..c73de3c997 100644 --- a/crates/nu-utils/standard_library/std.nu +++ b/crates/nu-utils/standard_library/std.nu @@ -391,33 +391,37 @@ def current-log-level [] { } } +def now [] { + date now | date format "%Y-%m-%dT%H:%M:%S%.3f" +} + # Log critical message export def "log critical" [message: string] { if (current-log-level) > (CRITICAL_LEVEL) { return } - print --stderr $"(ansi red_bold)CRIT ($message)(ansi reset)" + print --stderr $"(ansi red_bold)CRT|(now)|($message)(ansi reset)" } # Log error message export def "log error" [message: string] { if (current-log-level) > (ERROR_LEVEL) { return } - print --stderr $"(ansi red)ERROR ($message)(ansi reset)" + print --stderr $"(ansi red)ERR|(now)|($message)(ansi reset)" } # Log warning message export def "log warning" [message: string] { if (current-log-level) > (WARNING_LEVEL) { return } - print --stderr $"(ansi yellow)WARN ($message)(ansi reset)" + print --stderr $"(ansi yellow)WRN|(now)|($message)(ansi reset)" } # Log info message export def "log info" [message: string] { if (current-log-level) > (INFO_LEVEL) { return } - print --stderr $"(ansi white)INFO ($message)(ansi reset)" + print --stderr $"(ansi white)INF|(now)|($message)(ansi reset)" } # Log debug message export def "log debug" [message: string] { if (current-log-level) > (DEBUG_LEVEL) { return } - print --stderr $"(ansi default_dimmed)DEBUG ($message)(ansi reset)" + print --stderr $"(ansi default_dimmed)DBG|(now)|($message)(ansi reset)" } diff --git a/crates/nu-utils/standard_library/test_logger.nu b/crates/nu-utils/standard_library/test_logger.nu index fad163b7da..2a880a11ec 100644 --- a/crates/nu-utils/standard_library/test_logger.nu +++ b/crates/nu-utils/standard_library/test_logger.nu @@ -19,21 +19,21 @@ def "assert message" [system_level, message_level, message_level_str] { export def test_critical [] { assert no message 99 critical - assert message CRITICAL critical CRIT + assert message CRITICAL critical CRT } export def test_error [] { assert no message CRITICAL error - assert message ERROR error ERROR + assert message ERROR error ERR } export def test_warning [] { assert no message ERROR warning - assert message WARNING warning WARN + assert message WARNING warning WRN } export def test_info [] { assert no message WARNING info - assert message INFO info INFO + assert message INFO info "INF" #INF has to be quoted, otherwise it is the `inf` float } export def test_debug [] { assert no message INFO debug - assert message DEBUG debug DEBUG + assert message DEBUG debug DBG }