From 06540dfbce7ac0d02efef3a5fe02e9e295b276ff Mon Sep 17 00:00:00 2001 From: guilhermebodin Date: Thu, 14 Sep 2023 14:24:05 -0300 Subject: [PATCH] change the name to LoggingPolyglot --- .github/workflows/aqua.yml | 4 +- Project.toml | 2 +- README.md | 62 ++++++++-------- revise/revise.jl | 4 +- src/{Polyglot.jl => LoggingPolyglot.jl} | 2 +- src/logger.jl | 2 +- test/test_log_levels.jl | 60 ++++++++-------- test/test_logs.jl | 96 ++++++++++++------------- test/test_polyglot_logger.jl | 34 ++++----- test/test_set_Polyglot_constants.jl | 22 +++--- 10 files changed, 144 insertions(+), 144 deletions(-) rename src/{Polyglot.jl => LoggingPolyglot.jl} (88%) diff --git a/.github/workflows/aqua.yml b/.github/workflows/aqua.yml index 1d46300..52b05da 100644 --- a/.github/workflows/aqua.yml +++ b/.github/workflows/aqua.yml @@ -19,5 +19,5 @@ jobs: using Pkg Pkg.add(PackageSpec(name="Aqua")) Pkg.develop(PackageSpec(path=pwd())) - using Polyglot, Aqua - Aqua.test_all(Polyglot; unbound_args = false) \ No newline at end of file + using LoggingPolyglot, Aqua + Aqua.test_all(LoggingPolyglot; unbound_args = false) \ No newline at end of file diff --git a/Project.toml b/Project.toml index 368d534..ed7383d 100644 --- a/Project.toml +++ b/Project.toml @@ -1,4 +1,4 @@ -name = "Polyglot" +name = "LoggingPolyglot" uuid = "211639cc-9b11-4cfd-abc6-8f7477829344" version = "0.1.0" diff --git a/README.md b/README.md index 3d2cfaa..31f8963 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,10 @@ -# Polyglot.jl +# LoggingPolyglot.jl -[build-img]: https://github.com/psrenergy/Polyglot.jl/workflows/CI/badge.svg?branch=master -[build-url]: https://github.com/psrenergy/Polyglot.jl/actions?query=workflow%3ACI +[build-img]: https://github.com/psrenergy/LoggingPolyglot.jl/workflows/CI/badge.svg?branch=master +[build-url]: https://github.com/psrenergy/LoggingPolyglot.jl/actions?query=workflow%3ACI -[codecov-img]: https://codecov.io/gh/psrenergy/Polyglot.jl/coverage.svg?branch=master -[codecov-url]: https://codecov.io/gh/psrenergy/Polyglot.jl?branch=master +[codecov-img]: https://codecov.io/gh/psrenergy/LoggingPolyglot.jl/coverage.svg?branch=master +[codecov-url]: https://codecov.io/gh/psrenergy/LoggingPolyglot.jl?branch=master # StateSpaceModels.jl @@ -18,29 +18,29 @@ The package also helps users to deal with logs in multiple languages. ## Basic usage -Polyglot will log messages to different locations. +LoggingPolyglot will log messages to different locations. ```julia -import Polyglot +import LoggingPolyglot log_file = "my_application.log" -polyglot_logger = Polyglot.create_polyglot_logger(log_file) +polyglot_logger = LoggingPolyglot.create_polyglot_logger(log_file) # Only goes to file -Polyglot.debug("debug message") +LoggingPolyglot.debug("debug message") # Goes to file and console -Polyglot.info("info message") -Polyglot.warn("warn message") -Polyglot.non_fatal_error("error message") +LoggingPolyglot.info("info message") +LoggingPolyglot.warn("warn message") +LoggingPolyglot.non_fatal_error("error message") # Goes to console and file and then runs exit(1) if the session is not iterative. -Polyglot.fatal_error("Application cannot continue") +LoggingPolyglot.fatal_error("Application cannot continue") ``` ## Log in differnt languages -Polyglot stores some constants that help users deal with logs in different languages. +LoggingPolyglot stores some constants that help users deal with logs in different languages. ```julia log_path = "langs.log" @@ -54,16 +54,16 @@ langs_dict = Dict( "pt" => "O arquivo @@@ não existe.", ) ) -Polyglot.set_dict(langs_dict) -Polyglot.set_language("pt") -polyglot_logger = Polyglot.create_polyglot_logger(log_path) +LoggingPolyglot.set_dict(langs_dict) +LoggingPolyglot.set_language("pt") +polyglot_logger = LoggingPolyglot.create_polyglot_logger(log_path) # It will log the portuguese version "Olá!" -Polyglot.info(1) +LoggingPolyglot.info(1) # It will display the message "O arquivo file.txt não existe" -Polyglot.info(2, "file.txt") +LoggingPolyglot.info(2, "file.txt") ``` -One suggestion to store the codes ans messages for multiple languages is to store it on a TOML file. The function `Polyglot.set_dict` accepts the TOML path as input. +One suggestion to store the codes ans messages for multiple languages is to store it on a TOML file. The function `LoggingPolyglot.set_dict` accepts the TOML path as input. Dictionary TOML: ```toml @@ -80,18 +80,18 @@ Set dictionary from TOML: ```julia log_path = "langs.log" toml_dict_path = "example.toml" -Polyglot.set_dict(toml_dict_path) -Polyglot.set_language("pt") -polyglot_logger = Polyglot.create_polyglot_logger(log_path) +LoggingPolyglot.set_dict(toml_dict_path) +LoggingPolyglot.set_language("pt") +polyglot_logger = LoggingPolyglot.create_polyglot_logger(log_path) # It will log the portuguese version "Olá!" -Polyglot.info(1) +LoggingPolyglot.info(1) # It will display the message "O arquivo file.txt não existe" -Polyglot.info(2, "file.txt") +LoggingPolyglot.info(2, "file.txt") ``` ## Create logger -The arguments that can be passed using `Polyglot.create_polyglot_logger`: +The arguments that can be passed using `LoggingPolyglot.create_polyglot_logger`: * `log_file_path`: Log file path. This input must be passed * `min_level_console`: Minimum level shown in console. Default: Logging.Info * `min_level_file`: Minimum level shown in file. Default: Logging.Debug @@ -169,7 +169,7 @@ background_reverse_dict = Dict( ) log_file = "my_application.log" -Polyglot.create_polyglot_logger(log_file; level_dict, color_dict, background_reverse_dict) +LoggingPolyglot.create_polyglot_logger(log_file; level_dict, color_dict, background_reverse_dict) ``` The next example shows how to remove the `info` tag @@ -191,8 +191,8 @@ level_dict = Dict( "Error" => "Error", "Fatal Error" => "Fatal Error", ) -Polyglot.create_polyglot_logger(log_file; brackets_dict, level_dict) -Polyglot.info("info msg") -Polyglot.warn("warn msg") -Polyglot.remove_log_file_path_on_logger_creation(log_file) +LoggingPolyglot.create_polyglot_logger(log_file; brackets_dict, level_dict) +LoggingPolyglot.info("info msg") +LoggingPolyglot.warn("warn msg") +LoggingPolyglot.remove_log_file_path_on_logger_creation(log_file) ``` diff --git a/revise/revise.jl b/revise/revise.jl index 78d86dd..e52b679 100644 --- a/revise/revise.jl +++ b/revise/revise.jl @@ -8,8 +8,8 @@ dir_path = dirname(@__DIR__) Pkg.activate(dir_path) Pkg.instantiate() -using Polyglot +using LoggingPolyglot @info(""" -Polyglot +LoggingPolyglot """) diff --git a/src/Polyglot.jl b/src/LoggingPolyglot.jl similarity index 88% rename from src/Polyglot.jl rename to src/LoggingPolyglot.jl index df2b0c7..90742a3 100644 --- a/src/Polyglot.jl +++ b/src/LoggingPolyglot.jl @@ -1,4 +1,4 @@ -module Polyglot +module LoggingPolyglot using LoggingExtras using Dates diff --git a/src/logger.jl b/src/logger.jl index 43b7c0d..810415e 100644 --- a/src/logger.jl +++ b/src/logger.jl @@ -175,7 +175,7 @@ function create_polyglot_logger( level_to_print = choose_level_to_print(args.level, level_dict) open_bracket, close_bracket = get_tag_brackets(args.level, brackets_dict) space_before_msg = treat_empty_tag(level_to_print, close_bracket) - io = choose_terminal_io(args.level) # needed to use Polyglot in MD Studio. It takes stderr as error and stdout as non error log + io = choose_terminal_io(args.level) print(io, open_bracket) print_colored(io, level_to_print, args.level, color_dict, background_reverse_dict) println(io, close_bracket, space_before_msg, args.message) diff --git a/test/test_log_levels.jl b/test/test_log_levels.jl index c1b7f9f..4e62885 100644 --- a/test/test_log_levels.jl +++ b/test/test_log_levels.jl @@ -2,25 +2,25 @@ module TestLogLevels using Test using Logging -import Polyglot +import LoggingPolyglot function test_debug_levels_debug_with_level_999() log_path = "log_debug_levels_test.log" level = -1000 - polyglot_logger = Polyglot.create_polyglot_logger( + polyglot_logger = LoggingPolyglot.create_polyglot_logger( log_path; min_level_console = Logging.LogLevel(level), min_level_file = Logging.LogLevel(level), ) - Polyglot.debug("debug") - Polyglot.debug("debug -999"; level = -999) - Polyglot.debug("debug -1"; level = -1) + LoggingPolyglot.debug("debug") + LoggingPolyglot.debug("debug -999"; level = -999) + LoggingPolyglot.debug("debug -1"; level = -1) logs_on_file = readlines(log_path) @test length(logs_on_file) == 3 @test occursin("debug", logs_on_file[1]) @test occursin("debug -999", logs_on_file[2]) @test occursin("debug -1", logs_on_file[3]) - Polyglot.close_polyglot_logger(polyglot_logger) + LoggingPolyglot.close_polyglot_logger(polyglot_logger) rm(log_path) return nothing end @@ -28,18 +28,18 @@ end function test_debug_levels_2() log_path = "log_debug_levels_test.log" level = -100 - polyglot_logger = Polyglot.create_polyglot_logger( + polyglot_logger = LoggingPolyglot.create_polyglot_logger( log_path; min_level_console = Logging.LogLevel(level), min_level_file = Logging.LogLevel(level), ) - Polyglot.debug("debug") - Polyglot.debug("debug -999"; level = -999) - Polyglot.debug("debug -1"; level = -1) + LoggingPolyglot.debug("debug") + LoggingPolyglot.debug("debug -999"; level = -999) + LoggingPolyglot.debug("debug -1"; level = -1) logs_on_file = readlines(log_path) @test length(logs_on_file) == 1 @test occursin("debug -1", logs_on_file[1]) - Polyglot.close_polyglot_logger(polyglot_logger) + LoggingPolyglot.close_polyglot_logger(polyglot_logger) rm(log_path) return nothing end @@ -47,13 +47,13 @@ end function test_debug_levels_assertion_error_1() log_path = "test_debug_levels_assertion_error.log" level = -100 - polyglot_logger = Polyglot.create_polyglot_logger( + polyglot_logger = LoggingPolyglot.create_polyglot_logger( log_path; min_level_console = Logging.LogLevel(level), min_level_file = Logging.LogLevel(level), ) - @test_throws AssertionError Polyglot.debug("debug"; level = 1) - Polyglot.close_polyglot_logger(polyglot_logger) + @test_throws AssertionError LoggingPolyglot.debug("debug"; level = 1) + LoggingPolyglot.close_polyglot_logger(polyglot_logger) rm(log_path) return nothing end @@ -61,33 +61,33 @@ end function test_debug_levels_assertion_error_2() log_path = "test_debug_levels_assertion_error.log" level = -10000 - polyglot_logger = Polyglot.create_polyglot_logger( + polyglot_logger = LoggingPolyglot.create_polyglot_logger( log_path; min_level_console = Logging.LogLevel(level), min_level_file = Logging.LogLevel(level), ) - @test_throws AssertionError Polyglot.debug("debug"; level = -1001) - Polyglot.close_polyglot_logger(polyglot_logger) + @test_throws AssertionError LoggingPolyglot.debug("debug"; level = -1001) + LoggingPolyglot.close_polyglot_logger(polyglot_logger) rm(log_path) return nothing end function test_log_levels_on_file() log_path = "log_file_levels_test.log" - polyglot_logger = Polyglot.create_polyglot_logger( + polyglot_logger = LoggingPolyglot.create_polyglot_logger( log_path; min_level_console = Logging.Info, min_level_file = Logging.Warn, ) - Polyglot.debug("debug") - Polyglot.info("info") - Polyglot.warn("warn") - Polyglot.non_fatal_error("non_fatal_error") + LoggingPolyglot.debug("debug") + LoggingPolyglot.info("info") + LoggingPolyglot.warn("warn") + LoggingPolyglot.non_fatal_error("non_fatal_error") logs_on_file = readlines(log_path) @test length(logs_on_file) == 2 @test occursin("warn", logs_on_file[1]) @test occursin("non_fatal_error", logs_on_file[2]) - Polyglot.close_polyglot_logger(polyglot_logger) + LoggingPolyglot.close_polyglot_logger(polyglot_logger) rm(log_path) return nothing end @@ -101,19 +101,19 @@ function test_log_names_with_dict() "Error" => "error", ) log_path = "log_names_test.log" - polyglot_logger = Polyglot.create_polyglot_logger(log_path; level_dict = level_dict) - Polyglot.debug("test") - Polyglot.debug("test"; level = -100) - Polyglot.info("test") - Polyglot.warn("test") - Polyglot.non_fatal_error("test") + polyglot_logger = LoggingPolyglot.create_polyglot_logger(log_path; level_dict = level_dict) + LoggingPolyglot.debug("test") + LoggingPolyglot.debug("test"; level = -100) + LoggingPolyglot.info("test") + LoggingPolyglot.warn("test") + LoggingPolyglot.non_fatal_error("test") logs_on_file = readlines(log_path) @test occursin("[debug]", logs_on_file[1]) @test occursin("[debug level -100]", logs_on_file[2]) @test occursin("[info]", logs_on_file[3]) @test occursin("[warn]", logs_on_file[4]) @test occursin("[error]", logs_on_file[5]) - Polyglot.close_polyglot_logger(polyglot_logger) + LoggingPolyglot.close_polyglot_logger(polyglot_logger) rm(log_path) return nothing end diff --git a/test/test_logs.jl b/test/test_logs.jl index ca2f56b..dc928dd 100644 --- a/test/test_logs.jl +++ b/test/test_logs.jl @@ -1,61 +1,61 @@ module TestLogs using Test -import Polyglot +import LoggingPolyglot function test_direct_log_debug() log_debug_path = "debug.log" - polyglot_logger = Polyglot.create_polyglot_logger(log_debug_path) - Polyglot.debug("test message") + polyglot_logger = LoggingPolyglot.create_polyglot_logger(log_debug_path) + LoggingPolyglot.debug("test message") debug_on_file = readlines(log_debug_path) @test occursin("Debug", debug_on_file[1]) - Polyglot.close_polyglot_logger(polyglot_logger) + LoggingPolyglot.close_polyglot_logger(polyglot_logger) rm(log_debug_path; force = true) return nothing end function test_direct_log_info() log_info_path = "info.log" - polyglot_logger = Polyglot.create_polyglot_logger(log_info_path) - Polyglot.info("test message") + polyglot_logger = LoggingPolyglot.create_polyglot_logger(log_info_path) + LoggingPolyglot.info("test message") info_on_file = readlines(log_info_path) @test occursin("Info", info_on_file[1]) - Polyglot.close_polyglot_logger(polyglot_logger) + LoggingPolyglot.close_polyglot_logger(polyglot_logger) rm(log_info_path; force = true) return nothing end function test_direct_log_warn() log_warn_path = "warn.log" - polyglot_logger = Polyglot.create_polyglot_logger(log_warn_path) - Polyglot.warn("test message") + polyglot_logger = LoggingPolyglot.create_polyglot_logger(log_warn_path) + LoggingPolyglot.warn("test message") warn_on_file = readlines(log_warn_path) @test occursin("Warn", warn_on_file[1]) - Polyglot.close_polyglot_logger(polyglot_logger) + LoggingPolyglot.close_polyglot_logger(polyglot_logger) rm(log_warn_path; force = true) return nothing end function test_direct_log_error() log_error_path = "error.log" - polyglot_logger = Polyglot.create_polyglot_logger(log_error_path) - Polyglot.non_fatal_error("test message") + polyglot_logger = LoggingPolyglot.create_polyglot_logger(log_error_path) + LoggingPolyglot.non_fatal_error("test message") error_on_file = readlines(log_error_path) @test occursin("Error", error_on_file[1]) - Polyglot.close_polyglot_logger(polyglot_logger) + LoggingPolyglot.close_polyglot_logger(polyglot_logger) rm(log_error_path; force = true) return nothing end function test_different_logs_same_file() log_path = "test.log" - polyglot_logger = Polyglot.create_polyglot_logger(log_path) - Polyglot.info("test message") - Polyglot.warn("test message") + polyglot_logger = LoggingPolyglot.create_polyglot_logger(log_path) + LoggingPolyglot.info("test message") + LoggingPolyglot.warn("test message") logs_on_file = readlines(log_path) @test occursin("Info", logs_on_file[1]) @test occursin("Warn", logs_on_file[2]) - Polyglot.close_polyglot_logger(polyglot_logger) + LoggingPolyglot.close_polyglot_logger(polyglot_logger) rm(log_path; force = true) return nothing end @@ -72,13 +72,13 @@ function test_log_from_langs_dict() "pt" => "tchau!", ), ) - Polyglot.set_dict(langs_dict) - Polyglot.set_language("pt") - polyglot_logger = Polyglot.create_polyglot_logger(log_path) - Polyglot.info(1) + LoggingPolyglot.set_dict(langs_dict) + LoggingPolyglot.set_language("pt") + polyglot_logger = LoggingPolyglot.create_polyglot_logger(log_path) + LoggingPolyglot.info(1) logs_on_file = readlines(log_path) @test occursin("oi", logs_on_file[1]) - Polyglot.close_polyglot_logger(polyglot_logger) + LoggingPolyglot.close_polyglot_logger(polyglot_logger) rm(log_path; force = true) return nothing end @@ -95,11 +95,11 @@ function test_log_from_langs_dict_inexistent_code() "pt" => "tchau!", ), ) - Polyglot.set_dict(langs_dict) - Polyglot.set_language("pt") - polyglot_logger = Polyglot.create_polyglot_logger(log_path) - @test_throws ErrorException Polyglot.info(3) - Polyglot.close_polyglot_logger(polyglot_logger) + LoggingPolyglot.set_dict(langs_dict) + LoggingPolyglot.set_language("pt") + polyglot_logger = LoggingPolyglot.create_polyglot_logger(log_path) + @test_throws ErrorException LoggingPolyglot.info(3) + LoggingPolyglot.close_polyglot_logger(polyglot_logger) rm(log_path; force = true) return nothing end @@ -116,14 +116,14 @@ function test_log_from_langs_dict_debug_levels() "pt" => "tchau!", ), ) - Polyglot.set_dict(langs_dict) - Polyglot.set_language("pt") - polyglot_logger = Polyglot.create_polyglot_logger(log_path) - Polyglot.debug(1; level = -1) + LoggingPolyglot.set_dict(langs_dict) + LoggingPolyglot.set_language("pt") + polyglot_logger = LoggingPolyglot.create_polyglot_logger(log_path) + LoggingPolyglot.debug(1; level = -1) logs_on_file = readlines(log_path) @test length(logs_on_file) == 1 @test occursin("oi!", logs_on_file[1]) - Polyglot.close_polyglot_logger(polyglot_logger) + LoggingPolyglot.close_polyglot_logger(polyglot_logger) rm(log_path; force = true) return nothing end @@ -140,16 +140,16 @@ function test_log_from_langs_dict_with_interpolation() "pt" => "A usina térmica @@@ de código @@@ tem a capacidade inválida.", ), ) - Polyglot.set_dict(langs_dict) - Polyglot.set_language("pt") - polyglot_logger = Polyglot.create_polyglot_logger(log_path) - Polyglot.info(1, "10") - Polyglot.info(2, "UTE1", "2") + LoggingPolyglot.set_dict(langs_dict) + LoggingPolyglot.set_language("pt") + polyglot_logger = LoggingPolyglot.create_polyglot_logger(log_path) + LoggingPolyglot.info(1, "10") + LoggingPolyglot.info(2, "UTE1", "2") logs_on_file = readlines(log_path) @test occursin("Iteração 10", logs_on_file[1]) @test occursin("UTE1", logs_on_file[2]) @test occursin("2", logs_on_file[2]) - Polyglot.close_polyglot_logger(polyglot_logger) + LoggingPolyglot.close_polyglot_logger(polyglot_logger) rm(log_path; force = true) return nothing end @@ -166,12 +166,12 @@ function test_log_from_langs_dict_with_invalid_interpolation() "pt" => "A usina térmica @@@ de código @@@ tem a capacidade inválida.", ), ) - Polyglot.set_dict(langs_dict) - Polyglot.set_language("pt") - polyglot_logger = Polyglot.create_polyglot_logger(log_path) - @test_throws ErrorException Polyglot.info(1, "10", "oi", "tchau") - @test_throws ErrorException Polyglot.info(2, "UTE1") - Polyglot.close_polyglot_logger(polyglot_logger) + LoggingPolyglot.set_dict(langs_dict) + LoggingPolyglot.set_language("pt") + polyglot_logger = LoggingPolyglot.create_polyglot_logger(log_path) + @test_throws ErrorException LoggingPolyglot.info(1, "10", "oi", "tchau") + @test_throws ErrorException LoggingPolyglot.info(2, "UTE1") + LoggingPolyglot.close_polyglot_logger(polyglot_logger) rm(log_path; force = true) return nothing end @@ -195,15 +195,15 @@ function test_empty_brackets() ) logger_path = "brackets.log" - logger = Polyglot.create_polyglot_logger( + logger = LoggingPolyglot.create_polyglot_logger( logger_path; brackets_dict = brackets, level_dict = level, ) - Polyglot.info("empty brackets for info") - Polyglot.warn("brackets for warn") - Polyglot.close_polyglot_logger(logger) + LoggingPolyglot.info("empty brackets for info") + LoggingPolyglot.warn("brackets for warn") + LoggingPolyglot.close_polyglot_logger(logger) rm(logger_path; force = true) end diff --git a/test/test_polyglot_logger.jl b/test/test_polyglot_logger.jl index c1acb65..7076861 100644 --- a/test/test_polyglot_logger.jl +++ b/test/test_polyglot_logger.jl @@ -1,13 +1,13 @@ module TestPolyglot using Test -import Polyglot +import LoggingPolyglot function test_create_and_close_polyglot_logger() log_path = "test_log.log" - polyglot_logger = Polyglot.create_polyglot_logger(log_path) + polyglot_logger = LoggingPolyglot.create_polyglot_logger(log_path) @test isfile(log_path) - Polyglot.close_polyglot_logger(polyglot_logger) + LoggingPolyglot.close_polyglot_logger(polyglot_logger) rm(log_path) return nothing end @@ -15,12 +15,12 @@ end function test_create_two_polyglot_loggers_in_different_files() log_path1 = "test_log1.log" log_path2 = "test_log2.log" - polyglot_logger1 = Polyglot.create_polyglot_logger(log_path1) - polyglot_logger2 = Polyglot.create_polyglot_logger(log_path2) + polyglot_logger1 = LoggingPolyglot.create_polyglot_logger(log_path1) + polyglot_logger2 = LoggingPolyglot.create_polyglot_logger(log_path2) @test isfile(log_path1) @test isfile(log_path2) - Polyglot.close_polyglot_logger(polyglot_logger1) - Polyglot.close_polyglot_logger(polyglot_logger2) + LoggingPolyglot.close_polyglot_logger(polyglot_logger1) + LoggingPolyglot.close_polyglot_logger(polyglot_logger2) rm(log_path1) rm(log_path2) return nothing @@ -28,12 +28,12 @@ end function test_create_two_polyglot_loggers_in_the_same_file() log_path = "test_log.log" - polyglot_logger1 = Polyglot.create_polyglot_logger(log_path) + polyglot_logger1 = LoggingPolyglot.create_polyglot_logger(log_path) @test isfile(log_path) - polyglot_logger2 = Polyglot.create_polyglot_logger(log_path) + polyglot_logger2 = LoggingPolyglot.create_polyglot_logger(log_path) @test isfile(log_path) - Polyglot.close_polyglot_logger(polyglot_logger1) - Polyglot.close_polyglot_logger(polyglot_logger2) + LoggingPolyglot.close_polyglot_logger(polyglot_logger1) + LoggingPolyglot.close_polyglot_logger(polyglot_logger2) rm(log_path) return nothing end @@ -41,13 +41,13 @@ end function test_append_log_in_the_same_file() log_path = "test_log.log" - polyglot_logger1 = Polyglot.create_polyglot_logger(log_path) - Polyglot.info("old log") - Polyglot.close_polyglot_logger(polyglot_logger1) + polyglot_logger1 = LoggingPolyglot.create_polyglot_logger(log_path) + LoggingPolyglot.info("old log") + LoggingPolyglot.close_polyglot_logger(polyglot_logger1) - polyglot_logger2 = Polyglot.create_polyglot_logger(log_path; append_log = true) - Polyglot.info("new log") - Polyglot.close_polyglot_logger(polyglot_logger2) + polyglot_logger2 = LoggingPolyglot.create_polyglot_logger(log_path; append_log = true) + LoggingPolyglot.info("new log") + LoggingPolyglot.close_polyglot_logger(polyglot_logger2) logs_on_file = readlines(log_path) @test occursin("old log", logs_on_file[1]) diff --git a/test/test_set_Polyglot_constants.jl b/test/test_set_Polyglot_constants.jl index b870839..3358514 100644 --- a/test/test_set_Polyglot_constants.jl +++ b/test/test_set_Polyglot_constants.jl @@ -1,11 +1,11 @@ module TestConstants using Test -import Polyglot +import LoggingPolyglot function test_set_and_get_language() - Polyglot.set_language("pt") - @test Polyglot.get_language() == "pt" + LoggingPolyglot.set_language("pt") + @test LoggingPolyglot.get_language() == "pt" end function test_set_and_get_valid_dict() @@ -19,8 +19,8 @@ function test_set_and_get_valid_dict() "pt" => "tchau!", ), ) - Polyglot.set_dict(valid_dict) - @test Polyglot.get_dict() == valid_dict + LoggingPolyglot.set_dict(valid_dict) + @test LoggingPolyglot.get_dict() == valid_dict end function test_set_and_get_valid_dict_with_code_strings() @@ -34,8 +34,8 @@ function test_set_and_get_valid_dict_with_code_strings() "pt" => "tchau!", ), ) - Polyglot.set_dict(valid_dict) - @test Polyglot.get_dict() == valid_dict + LoggingPolyglot.set_dict(valid_dict) + @test LoggingPolyglot.get_dict() == valid_dict end function test_set_invalid_code_dict() @@ -45,7 +45,7 @@ function test_set_invalid_code_dict() "pt" => "oi!", ), ) - @test_throws ErrorException Polyglot.set_dict(invalid_dict) + @test_throws ErrorException LoggingPolyglot.set_dict(invalid_dict) end function test_set_invalid_language_dict() @@ -55,7 +55,7 @@ function test_set_invalid_language_dict() "pt" => "oi!", ), ) - @test_throws ErrorException Polyglot.set_dict(invalid_dict) + @test_throws ErrorException LoggingPolyglot.set_dict(invalid_dict) end function test_set_invalid_empty_language_dict() @@ -65,12 +65,12 @@ function test_set_invalid_empty_language_dict() "pt" => "oi!", ), ) - @test_throws ErrorException Polyglot.set_dict(invalid_dict) + @test_throws ErrorException LoggingPolyglot.set_dict(invalid_dict) end function test_set_empty_language_dict() invalid_dict = Dict() - @test_throws ErrorException Polyglot.set_dict(invalid_dict) + @test_throws ErrorException LoggingPolyglot.set_dict(invalid_dict) end function runtests()