From 92828b68f3b4bac50441934d570b32b64dd9982a Mon Sep 17 00:00:00 2001 From: Filippo Vicentini Date: Fri, 24 May 2019 13:33:34 +0200 Subject: [PATCH 1/2] Add pretty-printing to `TBLogger` object --- src/TBLogger.jl | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/TBLogger.jl b/src/TBLogger.jl index 7f66510..9071120 100644 --- a/src/TBLogger.jl +++ b/src/TBLogger.jl @@ -231,3 +231,28 @@ function handle_message(lg::TBLogger, level, message, _module, group, id, file, iter = increment_step!(lg, i_step) write_event(lg.file, make_event(lg, summ, step=iter)) end + +Base.print(io::IO, tbl::TBLogger) = + Base.print(io, "TBLogger(min_leel=$(tbl.min_level), step=$(tbl.global_step))") + +Base.show(io::IO, tbl::TBLogger) = begin + str = """ + TBLogger: + - Log level : $(tbl.min_level) + - Current step : $(tbl.global_step) + - Output : $(tbl.logdir) + - open files : $(length(tbl.all_files)) + """ + Base.show(io, "hey\ncia") +end + +Base.show(io::IO, mime::MIME"text/plain", tbl::TBLogger) = begin + str = """ + TBLogger: + - Log level : $(tbl.min_level) + - Current step : $(tbl.global_step) + - Output : $(tbl.logdir) + - open files : $(length(tbl.all_files)) + """ + Base.print(io, str) +end From ac29dd6de01106ea3b95f7be6a05cd44a5ded82f Mon Sep 17 00:00:00 2001 From: Filippo Vicentini Date: Fri, 24 May 2019 17:29:08 +0200 Subject: [PATCH 2/2] Fix show method to respect julia guidelines --- src/TBLogger.jl | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/src/TBLogger.jl b/src/TBLogger.jl index 9071120..1b86f92 100644 --- a/src/TBLogger.jl +++ b/src/TBLogger.jl @@ -232,26 +232,19 @@ function handle_message(lg::TBLogger, level, message, _module, group, id, file, write_event(lg.file, make_event(lg, summ, step=iter)) end -Base.print(io::IO, tbl::TBLogger) = - Base.print(io, "TBLogger(min_leel=$(tbl.min_level), step=$(tbl.global_step))") - +######################### Methods for pretty printing ########################## Base.show(io::IO, tbl::TBLogger) = begin - str = """ - TBLogger: - - Log level : $(tbl.min_level) - - Current step : $(tbl.global_step) - - Output : $(tbl.logdir) - - open files : $(length(tbl.all_files)) - """ - Base.show(io, "hey\ncia") + str = "TBLogger(\"$(tbl.logdir)\"), min_level=$(tbl.min_level), "* + "purge_step=$(tbl.global_step))" + Base.print(io, str) end Base.show(io::IO, mime::MIME"text/plain", tbl::TBLogger) = begin str = """ TBLogger: - - Log level : $(tbl.min_level) - - Current step : $(tbl.global_step) - - Output : $(tbl.logdir) + - Log level : $(tbl.min_level) + - Current step : $(tbl.global_step) + - Output : $(tbl.logdir) - open files : $(length(tbl.all_files)) """ Base.print(io, str)