Skip to content

Commit

Permalink
Merge branch 'master' into gb/add_success_level
Browse files Browse the repository at this point in the history
  • Loading branch information
guilhermebodin authored Dec 8, 2023
2 parents 3579e63 + f822c0c commit 5067a46
Show file tree
Hide file tree
Showing 12 changed files with 62 additions and 69 deletions.
23 changes: 0 additions & 23 deletions .github/workflows/aqua.yml

This file was deleted.

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}",
}
8 changes: 7 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,17 @@ LoggingExtras = "e6f89c97-d47a-5376-807f-9c37f3926c36"
TOML = "fa267f1f-6049-4f14-aa54-33bafae1ed76"

[compat]
Aqua = "0.8"
Dates = "1"
Logging = "1"
LoggingExtras = "1"
Test = "1"
TOML = "1"
julia = "1.7"

[extras]
Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
test = ["Test"]
test = ["Aqua", "Test"]
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,13 +1,13 @@
const FATAL_ERROR_LEVEL = Logging.LogLevel(3000)
const SUCCESS_LEVEL = Logging.LogLevel(1)

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 @@ -71,9 +71,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 @@ -63,7 +63,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 @@ -180,7 +180,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 @@ -190,9 +190,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
9 changes: 9 additions & 0 deletions src/logs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,27 @@ 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 success(msg::AbstractString)
@logmsg Logging.LogLevel(SUCCESS_LEVEL) 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 @@ -84,21 +89,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
25 changes: 18 additions & 7 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,12 +1,23 @@
import LoggingPolyglot

using Aqua
using Test

for file in readdir(@__DIR__)
if file in ["runtests.jl"]
continue
elseif !endswith(file, ".jl")
continue
function testall()
@testset "Aqua.jl" begin
Aqua.test_all(LoggingPolyglot)
end
@testset "$(file)" begin
include(file)

for file in readdir(@__DIR__)
if file in ["runtests.jl"]
continue
elseif !endswith(file, ".jl")
continue
end
@testset "$(file)" begin
include(file)
end
end
end

testall()
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 5067a46

Please sign in to comment.