Skip to content

Commit

Permalink
respect maxlog keyword for logs, fixes #1858
Browse files Browse the repository at this point in the history
  • Loading branch information
Pangoraw committed Jan 30, 2022
1 parent 0e4cc35 commit 309703b
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 1 deletion.
14 changes: 14 additions & 0 deletions src/evaluation/WorkspaceManager.jl
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,20 @@ function start_relaying_logs((session, notebook)::SN, log_channel::Distributed.R
end
end

maybe_max_log = findfirst(((key, _),) -> key == "maxlog", next_log["kwargs"])
if maybe_max_log !== nothing
n_logs = count(log -> log["id"] == next_log["id"], running_cell.logs)
try
max_log = parse(Int, next_log["kwargs"][maybe_max_log][2] |> first)

# Don't show message with id more than max_log times
if max_log isa Int && n_logs >= max_log
return
end
catch
end
end

push!(running_cell.logs, next_log)
Pluto.@asynclog update_throttled()
catch e
Expand Down
2 changes: 1 addition & 1 deletion src/runner/PlutoRunner.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2005,7 +2005,7 @@ function Logging.handle_message(::PlutoLogger, level, msg, _module, group, id, f
"file" => file,
"cell_id" => currently_running_cell_id[],
"line" => line,
"kwargs" => Any[(string(k), format_output_default(v)) for (k, v) in kwargs],
"kwargs" => Tuple{String,Any}[(string(k), format_output_default(v)) for (k, v) in kwargs],
)
)

Expand Down
29 changes: 29 additions & 0 deletions test/Logging.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using Test
import UUIDs
import Pluto: PlutoRunner, Notebook, WorkspaceManager, Cell, ServerSession, ClientSession, update_run!

@testset "Logging" begin
🍭 = ServerSession()
🍭.options.evaluation.workspace_use_distributed = true

fakeclient = ClientSession(:fake, nothing)
🍭.connected_clients[fakeclient.id] = fakeclient

@testset "Logging respects maxlog" begin
notebook = Notebook(Cell.([
"""
for i in 1:10
@info "logging" i maxlog=2
end
""",
]))

update_run!(🍭, notebook, notebook.cells)
@test notebook.cells[begin] |> noerror

sleep(.1)

@test length(notebook.cells[begin].logs) == 2
WorkspaceManager.unmake_workspace((🍭, notebook))
end
end
2 changes: 2 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ include("./Dynamic.jl")
verify_no_running_processes()
include("./MacroAnalysis.jl")
verify_no_running_processes()
include("./Logging.jl")
verify_no_running_processes()
include("./webserver.jl")
verify_no_running_processes()
include("./Notebook.jl")
Expand Down

0 comments on commit 309703b

Please sign in to comment.