diff --git a/Project.toml b/Project.toml index 564bc2d..76e1163 100644 --- a/Project.toml +++ b/Project.toml @@ -1,6 +1,6 @@ name = "LoggingPolyglot" uuid = "211639cc-9b11-4cfd-abc6-8f7477829344" -version = "0.2.0" +version = "0.2.1" [deps] Dates = "ade2ca70-3891-5945-98fb-dc099432e06a" diff --git a/src/constants.jl b/src/constants.jl index dea1f6f..366f868 100644 --- a/src/constants.jl +++ b/src/constants.jl @@ -1,6 +1,6 @@ const FatalErrorLevel = Logging.LogLevel(3000) -function set_language(lang::String) +function set_language(lang::AbstractString) POLYGLOT_LANG[1] = lang return lang end @@ -57,7 +57,7 @@ function set_dict(dict::Dict) return dict end -function set_dict(toml_dict_path::String) +function set_dict(toml_dict_path::AbstractString) dict = toml_file_to_dict(toml_dict_path) if !is_valid_dict(dict) error("The dictionary of codes and language is invalid.") @@ -70,7 +70,7 @@ function get_dict() return POLYGLOT_LOG_DICT[1] end -function toml_file_to_dict(toml_dict_path::String) +function toml_file_to_dict(toml_dict_path::AbstractString) @assert isfile(toml_dict_path) toml_dict = TOML.parsefile(toml_dict_path) new_dict = Dict{Int, Dict{String, String}}() diff --git a/src/logger.jl b/src/logger.jl index dae7c09..7038be6 100644 --- a/src/logger.jl +++ b/src/logger.jl @@ -13,11 +13,11 @@ function close_polyglot_logger(logger::TeeLogger) end """ -remove_log_file_path_on_logger_creation(log_file_path::String) +remove_log_file_path_on_logger_creation(log_file_path::AbstractString) * `log_file_path`: Remove log file in path log_file_path """ -function remove_log_file_path_on_logger_creation(log_file_path::String) +function remove_log_file_path_on_logger_creation(log_file_path::AbstractString) try if global_logger() isa TeeLogger close_polyglot_logger(global_logger()) @@ -69,7 +69,7 @@ function get_tag_brackets(level::LogLevel, brackets_dict::Dict) end end -function treat_empty_tag(level_to_print::String, close_bracket::String) +function treat_empty_tag(level_to_print::AbstractString, close_bracket::AbstractString) if level_to_print == "" && close_bracket == "" return "" else @@ -79,7 +79,7 @@ end """ create_polyglot_logger( - log_file_path::String; + log_file_path::AbstractString; min_level_console::Logging.LogLevel, min_level_file::Logging.LogLevel, brackets, @@ -129,7 +129,7 @@ end ) """ function create_polyglot_logger( - log_file_path::String; + log_file_path::AbstractString; min_level_console::Logging.LogLevel = Logging.Info, min_level_file::Logging.LogLevel = Logging.Debug, append_log::Bool = false, @@ -209,7 +209,7 @@ end function print_colored( io::IO, - str::String, + str::AbstractString, level::Logging.LogLevel, color_dict::Dict{String, Symbol}, reverse_dict::Dict{String, Bool}, @@ -223,7 +223,12 @@ function print_colored( return nothing end -function print_colored(io::IO, str::String; color::Symbol = :normal, reverse::Bool = false) +function print_colored( + io::IO, + str::AbstractString; + color::Symbol = :normal, + reverse::Bool = false, +) if color == :normal && reverse == false print(io, str) else diff --git a/src/logs.jl b/src/logs.jl index 3e8fa6f..693396b 100644 --- a/src/logs.jl +++ b/src/logs.jl @@ -1,29 +1,32 @@ # Direct logs -function debug(msg::String; level::Int = -1000) +function debug(msg::AbstractString; level::Integer = -1000) @assert Logging.Debug <= Logging.LogLevel(level) < Logging.Info @logmsg Logging.LogLevel(level) msg return nothing end -function info(msg::String) +function info(msg::AbstractString) @info msg return nothing end -function warn(msg::String) +function warn(msg::AbstractString) @warn msg return nothing end -function non_fatal_error(msg::String) +function non_fatal_error(msg::AbstractString) @error msg return nothing end -function fatal_error(msg::String; exception::Exception = ErrorException("Fatal error")) +function fatal_error( + msg::AbstractString; + exception::Exception = ErrorException("Fatal error"), +) @logmsg FatalErrorLevel msg throw(exception) return nothing end # logs via code and language -function get_raw_message(dict::Dict, code::Int, lang::String) +function get_raw_message(dict::Dict, code::Integer, lang::AbstractString) if haskey(dict, code) # Code could be an Int langs_dict = dict[code] if haskey(langs_dict, lang) @@ -43,7 +46,7 @@ function get_raw_message(dict::Dict, code::Int, lang::String) end end -function prepare_msg(code::Int, replacements...) +function prepare_msg(code::Integer, replacements...) dict = get_dict() lang = get_language() raw_message = get_raw_message(dict, code, lang) @@ -51,7 +54,7 @@ function prepare_msg(code::Int, replacements...) return treated_message end -function treat_message(raw_message::String, replacements...) +function treat_message(raw_message::AbstractString, replacements...) splitted_message = split(raw_message, "@@@") num_correct_replacements = length(splitted_message) - 1 # If the is no @@@ in the message we can return the raw_message @@ -69,28 +72,28 @@ function treat_message(raw_message::String, replacements...) return treated_message end -function debug(code::Int, replacements...; level::Int = -1000) +function debug(code::Integer, replacements...; level::Integer = -1000) msg = prepare_msg(code, replacements...) debug(msg; level) return nothing end -function info(code::Int, replacements...) +function info(code::Integer, replacements...) msg = prepare_msg(code, replacements...) info(msg) return nothing end -function warn(code::Int, replacements...) +function warn(code::Integer, replacements...) msg = prepare_msg(code, replacements...) warn(msg) return nothing end -function non_fatal_error(code::Int, replacements...) +function non_fatal_error(code::Integer, replacements...) msg = prepare_msg(code, replacements...) non_fatal_error(msg) return nothing end function fatal_error( - code::Int, + code::Integer, replacements...; exception::Exception = ErrorException("Fatal error"), )