diff --git a/src/constants.jl b/src/constants.jl index aadc365..c75f3c2 100644 --- a/src/constants.jl +++ b/src/constants.jl @@ -1,4 +1,5 @@ -const FatalErrorLevel = Logging.LogLevel(3000) +const FATAL_ERROR_LEVEL = Logging.LogLevel(3000) +const SUCCESS_LEVEL = Logging.LogLevel(1) function set_language(language::AbstractString) POLYGLOT_LANGUAGE[1] = language diff --git a/src/logger.jl b/src/logger.jl index c55b3a5..876d447 100644 --- a/src/logger.jl +++ b/src/logger.jl @@ -49,13 +49,15 @@ function choose_terminal_io(level::LogLevel) end function get_level_string(level::LogLevel) - if Logging.Info <= level <= Logging.Error || level == Logging.Debug - return string(level) + if level == SUCCESS_LEVEL + return "Success" + elseif level == FATAL_ERROR_LEVEL + return "Fatal Error" elseif Logging.Debug < level < Logging.Info return "Debug Level" - elseif level == FatalErrorLevel - return "Fatal Error" - end + else + string(level) + end end function get_tag_brackets(level::LogLevel, brackets_dict::Dict) @@ -97,6 +99,7 @@ end "Debug Level" => ["[", "]"], "Debug" => ["[", "]"], "Info" => ["[", "]"], + "Success" => ["[", "]"], "Warn" => ["[", "]"], "Error" => ["[", "]"], "Fatal Error" => ["[", "]"], @@ -106,6 +109,7 @@ end "Debug Level" => "Debug Level", "Debug" => "Debug", "Info" => "Info", + "Success" => "Success", "Warn" => "Warn", "Error" => "Error" ) @@ -114,6 +118,7 @@ end "Debug Level" => :cyan, "Debug" => :cyan, "Info" => :cyan, + "Success" => :green, "Warn" => :yellow, "Error" => :red, "Fatal Error" => :red @@ -123,6 +128,7 @@ end "Debug Level" => false, "Debug" => false, "Info" => false, + "Success" => false, "Warn" => false, "Error" => false, "Fatal Error" => true @@ -137,6 +143,7 @@ function create_polyglot_logger( "Debug Level" => ["[", "]"], "Debug" => ["[", "]"], "Info" => ["[", "]"], + "Success" => ["[", "]"], "Warn" => ["[", "]"], "Error" => ["[", "]"], "Fatal Error" => ["[", "]"], @@ -145,6 +152,7 @@ function create_polyglot_logger( "Debug Level" => "Debug Level", "Debug" => "Debug", "Info" => "Info", + "Success" => "Success", "Warn" => "Warn", "Error" => "Error", "Fatal Error" => "Fatal Error", @@ -153,6 +161,7 @@ function create_polyglot_logger( "Debug Level" => :cyan, "Debug" => :cyan, "Info" => :cyan, + "Success" => :green, "Warn" => :yellow, "Error" => :red, "Fatal Error" => :red, @@ -161,6 +170,7 @@ function create_polyglot_logger( "Debug Level" => false, "Debug" => false, "Info" => false, + "Success" => false, "Warn" => false, "Error" => false, "Fatal Error" => true, diff --git a/src/logs.jl b/src/logs.jl index 3454bbb..6211b8e 100644 --- a/src/logs.jl +++ b/src/logs.jl @@ -10,6 +10,11 @@ function info(msg::AbstractString) return nothing end +function success(msg::AbstractString) + @logmsg Logging.LogLevel(SUCCESS_LEVEL) msg + return nothing +end + function warn(msg::AbstractString) @warn msg return nothing @@ -24,10 +29,10 @@ function fatal_error( msg::AbstractString; exception::Exception = ErrorException("Fatal error"), ) + @logmsg FATAL_ERROR_LEVEL msg + logger = Logging.global_logger() close_polyglot_logger(logger) - - @logmsg FatalErrorLevel msg throw(exception) return nothing end diff --git a/test/test_log_levels.jl b/test/test_log_levels.jl index b00bbc8..a014ca2 100644 --- a/test/test_log_levels.jl +++ b/test/test_log_levels.jl @@ -81,6 +81,7 @@ function test_log_levels_on_file() ) LoggingPolyglot.debug("debug") LoggingPolyglot.info("info") + LoggingPolyglot.success("success") LoggingPolyglot.warn("warn") LoggingPolyglot.non_fatal_error("non_fatal_error") logs_on_file = readlines(log_path)