mirror of
https://github.com/ANL-CEEESA/UnitCommitment.jl.git
synced 2025-12-06 00:08:52 -06:00
Make logs more colorful
This commit is contained in:
16
src/log.jl
16
src/log.jl
@@ -35,8 +35,17 @@ function handle_message(logger::TimeLogger,
|
|||||||
kwargs...)
|
kwargs...)
|
||||||
elapsed_time = time() - logger.initial_time
|
elapsed_time = time() - logger.initial_time
|
||||||
time_string = @sprintf("[%12.3f] ", elapsed_time)
|
time_string = @sprintf("[%12.3f] ", elapsed_time)
|
||||||
|
|
||||||
|
if level >= Logging.Error
|
||||||
|
color = :light_red
|
||||||
|
elseif level >= Logging.Warn
|
||||||
|
color = :light_yellow
|
||||||
|
else
|
||||||
|
color = :light_green
|
||||||
|
end
|
||||||
|
|
||||||
if level >= logger.screen_log_level
|
if level >= logger.screen_log_level
|
||||||
print(time_string)
|
printstyled(time_string, color=color)
|
||||||
println(message)
|
println(message)
|
||||||
end
|
end
|
||||||
if logger.file !== nothing && level >= logger.io_log_level
|
if logger.file !== nothing && level >= logger.io_log_level
|
||||||
@@ -47,4 +56,9 @@ function handle_message(logger::TimeLogger,
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function setup_logger()
|
||||||
|
initial_time = time()
|
||||||
|
global_logger(TimeLogger(initial_time=initial_time))
|
||||||
|
end
|
||||||
|
|
||||||
export TimeLogger
|
export TimeLogger
|
||||||
@@ -3,6 +3,9 @@
|
|||||||
# Released under the modified BSD license. See COPYING.md for more details.
|
# Released under the modified BSD license. See COPYING.md for more details.
|
||||||
|
|
||||||
using Test
|
using Test
|
||||||
|
using UnitCommitment
|
||||||
|
|
||||||
|
UnitCommitment.setup_logger()
|
||||||
|
|
||||||
@testset "UnitCommitment" begin
|
@testset "UnitCommitment" begin
|
||||||
include("instance_test.jl")
|
include("instance_test.jl")
|
||||||
|
|||||||
Reference in New Issue
Block a user