Skip to content

Commit

Permalink
Updates
Browse files Browse the repository at this point in the history
  • Loading branch information
raphasampaio committed Dec 8, 2023
1 parent 149e6ac commit c791c89
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 38 deletions.
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"julia.executablePath": "${env:JULIA_194}",
}
2 changes: 1 addition & 1 deletion formatter/format.bat
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

SET FORMATTER_DIR=%~dp0

julia --project=%FORMATTER_DIR% %FORMATTER_DIR%\format.jl
CALL "%JULIA_194%" --project=%FORMATTER_DIR% %FORMATTER_DIR%\format.jl
21 changes: 1 addition & 20 deletions formatter/format.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,4 @@ Pkg.instantiate()

using JuliaFormatter

import Pkg
Pkg.instantiate()

using JuliaFormatter

function apply_formatter()
# 3 times to converge formatting is an heuristic
println("Formatting src and test folders")
for _ in 1:2
format(joinpath(dirname(@__DIR__), "src"))
format(joinpath(dirname(@__DIR__), "test"))
end
formatted_src = format(joinpath(dirname(@__DIR__), "src"))
formatted_test = format(joinpath(dirname(@__DIR__), "test"))
println("src folder formatted: $formatted_src")
println("test folder formatted: $formatted_test")
return nothing
end

apply_formatter()
format(dirname(@__DIR__))
2 changes: 1 addition & 1 deletion revise/revise.bat
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

SET BASEPATH=%~dp0

%JULIA_190% --color=yes --project=%BASEPATH% --load=%BASEPATH%\revise.jl
CALL "%JULIA_194%" --project=%BASEPATH% --load=%BASEPATH%\revise.jl
2 changes: 1 addition & 1 deletion src/LoggingPolyglot.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ using LoggingExtras
using Dates
using TOML

const POLYGLOT_LANG = String["en"]
const POLYGLOT_LANGUAGE = String["en"]
const POLYGLOT_LOG_DICT = [Dict()]

include("constants.jl")
Expand Down
14 changes: 7 additions & 7 deletions src/constants.jl
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
const FatalErrorLevel = Logging.LogLevel(3000)

function set_language(lang::AbstractString)
POLYGLOT_LANG[1] = lang
return lang
function set_language(language::AbstractString)
POLYGLOT_LANGUAGE[1] = language
return language
end

function get_language()
return POLYGLOT_LANG[1]
return POLYGLOT_LANGUAGE[1]
end

function is_valid_dict(dict::Dict)::Bool
Expand Down Expand Up @@ -70,9 +70,9 @@ function get_dict()
return POLYGLOT_LOG_DICT[1]
end

function toml_file_to_dict(toml_dict_path::AbstractString)
@assert isfile(toml_dict_path)
toml_dict = TOML.parsefile(toml_dict_path)
function toml_file_to_dict(path::AbstractString)
@assert isfile(path)
toml_dict = TOML.parsefile(path)
new_dict = Dict{Int, Dict{String, String}}()
for (k, v) in toml_dict
new_key = parse(Int, k)
Expand Down
17 changes: 9 additions & 8 deletions src/logger.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,19 @@ function close_polyglot_logger(logger::TeeLogger)
end

"""
remove_log_file_path_on_logger_creation(log_file_path::AbstractString)
remove_log_file_path_on_logger_creation(path::AbstractString)
* `log_file_path`: Remove log file in path log_file_path
* `path`: Path to log file to be removed
"""
function remove_log_file_path_on_logger_creation(log_file_path::AbstractString)
function remove_log_file_path_on_logger_creation(path::AbstractString)
try
if global_logger() isa TeeLogger
close_polyglot_logger(global_logger())
rm(log_file_path; force = true)
rm(path; force = true)
end
catch err
if isa(err, Base.IOError)
error("Cannot create a logger if $log_file_path still has IOStreams open.")
error("Cannot create a logger if $path still has IOStreams open.")
end
end
return nothing
Expand Down Expand Up @@ -61,7 +61,7 @@ end
function get_tag_brackets(level::LogLevel, brackets_dict::Dict)
level_str = get_level_string(level)
tag_brackets = brackets_dict[level_str]
# If brackets are empty return empty strings

if !isempty(tag_brackets)
return tag_brackets
else
Expand Down Expand Up @@ -170,7 +170,7 @@ function create_polyglot_logger(
remove_log_file_path_on_logger_creation(log_file_path)
end

# Console logger only min_level_console and up
# console logger only min_level_console and up
format_logger_console = FormatLogger() do io, args
level_to_print = choose_level_to_print(args.level, level_dict)
open_bracket, close_bracket = get_tag_brackets(args.level, brackets_dict)
Expand All @@ -180,9 +180,10 @@ function create_polyglot_logger(
print_colored(io, level_to_print, args.level, color_dict, background_reverse_dict)
println(io, close_bracket, space_before_msg, args.message)
end

console_logger = MinLevelLogger(format_logger_console, min_level_console)

# File logger logs min_level_file and up
# file logger logs min_level_file and up
format_logger_file = FormatLogger(log_file_path; append = true) do io, args
level_to_print = choose_level_to_print(args.level, level_dict)
open_bracket, close_bracket = get_tag_brackets(args.level, brackets_dict)
Expand Down
8 changes: 8 additions & 0 deletions src/logs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,22 @@ function debug(msg::AbstractString; level::Integer = -1000)
@logmsg Logging.LogLevel(level) msg
return nothing
end

function info(msg::AbstractString)
@info msg
return nothing
end

function warn(msg::AbstractString)
@warn msg
return nothing
end

function non_fatal_error(msg::AbstractString)
@error msg
return nothing
end

function fatal_error(
msg::AbstractString;
exception::Exception = ErrorException("Fatal error"),
Expand Down Expand Up @@ -80,21 +84,25 @@ function debug(code::Integer, replacements...; level::Integer = -1000)
debug(msg; level)
return nothing
end

function info(code::Integer, replacements...)
msg = prepare_msg(code, replacements...)
info(msg)
return nothing
end

function warn(code::Integer, replacements...)
msg = prepare_msg(code, replacements...)
warn(msg)
return nothing
end

function non_fatal_error(code::Integer, replacements...)
msg = prepare_msg(code, replacements...)
non_fatal_error(msg)
return nothing
end

function fatal_error(
code::Integer,
replacements...;
Expand Down
5 changes: 5 additions & 0 deletions test/test.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@echo off

SET BASEPATH=%~dp0

CALL "%JULIA_194%" --project=%BASEPATH%\.. -e "import Pkg; Pkg.test()"

0 comments on commit c791c89

Please sign in to comment.