Skip to content

Commit 1988a21

Browse files
authored
Support prepend argument in TBLogger constructor (#101)
* Support prepend argument in TBLogger constructor * Review fixes
1 parent 006450e commit 1988a21

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

src/TBLogger.jl

+7-2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export tb_append, tb_overwrite, tb_increment
2020
"""
2121
TBLogger(logdir[, tb_increment];
2222
time=time(),
23+
prefix="",
2324
purge_step=nothing,
2425
step_increment=1,
2526
min_level=Logging.Info)
@@ -29,20 +30,24 @@ argument specifies the behaviour if the `logdir` already exhists: the default
2930
choice `tb_increment` appends an increasing number 1,2... to `logdir`. Other
3031
choices are `tb_overwrite`, which overwrites the previous folder, and `tb_append`.
3132
33+
Optional keyword argument `prefix` can be passed to prepend a path to the file
34+
name (note, not the log directory). See `create_eventfile()`
35+
3236
If a `purge_step::Int` is passed, every step before `purge_step` will be ignored
3337
by tensorboard (usefull in the case of restarting a crashed computation).
3438
3539
`min_level` specifies the minimum level of messages logged to
3640
tensorboard.
3741
"""
3842
function TBLogger(logdir="tensorboard_logs/run", overwrite=tb_increment;
39-
time=time(),
43+
time=time(),
44+
prefix="",
4045
purge_step::Union{Int,Nothing}=nothing,
4146
step_increment = 1,
4247
min_level::LogLevel=Info)
4348

4449
logdir = init_logdir(logdir, overwrite)
45-
fpath, evfile = create_eventfile(logdir, purge_step, time)
50+
fpath, evfile = create_eventfile(logdir, purge_step, time; prepend = prefix)
4651

4752
all_files = Dict(fpath => evfile)
4853
start_step = something(purge_step, 0)

test/test_TBLogger.jl

+5
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,15 @@ test_log_dir = "test_logs/"
2020
tbl4 = TBLogger(test_log_dir*"run_2", tb_overwrite)
2121
@test !isfile(test_log_dir*"run_2/testfile")
2222

23+
# check custom file prefix
24+
tbl5 = TBLogger(test_log_dir*"run_3"; time = 0, prefix = "test.")
25+
@test isfile(test_log_dir*"run_3/test.events.out.tfevents.0.$(gethostname())")
26+
2327
# close all event files
2428
close.(values(tbl1.all_files))
2529
close.(values(tbl2.all_files))
2630
close.(values(tbl4.all_files))
31+
close.(values(tbl5.all_files))
2732
end
2833

2934
@testset "create log directory" begin

0 commit comments

Comments
 (0)