Datasets:
Download src/utils/log.jl from EridanusQ/UnitCommitment_Trajectory: direct link, hf CLI and curl.
- Browser
- Download file 1.68 kB
-
https://huggingface.co/datasets/EridanusQ/UnitCommitment_Trajectory/resolve/main/src/utils/log.jl
- Command line
-
hf download hf://datasets/EridanusQ/UnitCommitment_Trajectory/src/utils/log.jl
-
curl -L -o log.jl https://huggingface.co/datasets/EridanusQ/UnitCommitment_Trajectory/resolve/main/src/utils/log.jl
1.68 kB
| # UnitCommitment.jl: Optimization Package for Security-Constrained Unit Commitment | |
| # Copyright (C) 2020, UChicago Argonne, LLC. All rights reserved. | |
| # Released under the modified BSD license. See COPYING.md for more details. | |
| import Logging: min_enabled_level, shouldlog, handle_message | |
| using Base.CoreLogging, Logging, Printf | |
| Base. struct TimeLogger <: AbstractLogger | |
| initial_time::Float64 | |
| file::Union{Nothing,IOStream} = nothing | |
| screen_log_level::Any = CoreLogging.Info | |
| io_log_level::Any = CoreLogging.Info | |
| end | |
| min_enabled_level(logger::TimeLogger) = logger.io_log_level | |
| shouldlog(logger::TimeLogger, level, _module, group, id) = true | |
| function handle_message( | |
| logger::TimeLogger, | |
| level, | |
| message, | |
| _module, | |
| group, | |
| id, | |
| filepath, | |
| line; | |
| kwargs..., | |
| ) | |
| elapsed_time = time() - logger.initial_time | |
| time_string = ("[%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 | |
| printstyled(time_string, color = color) | |
| println(message) | |
| flush(stdout) | |
| flush(stderr) | |
| Base.Libc.flush_cstdio() | |
| end | |
| if logger.file !== nothing && level >= logger.io_log_level | |
| write(logger.file, time_string) | |
| write(logger.file, message) | |
| write(logger.file, "\n") | |
| flush(logger.file) | |
| end | |
| end | |
| function _setup_logger(; level = CoreLogging.Info) | |
| initial_time = time() | |
| return global_logger( | |
| TimeLogger(initial_time = initial_time, screen_log_level = level), | |
| ) | |
| end | |