From 309703b9698bf094c77bca0bbc7ac98698c56e51 Mon Sep 17 00:00:00 2001 From: Paul Date: Sun, 30 Jan 2022 20:46:58 +0100 Subject: [PATCH] respect maxlog keyword for logs, fixes #1858 --- src/evaluation/WorkspaceManager.jl | 14 ++++++++++++++ src/runner/PlutoRunner.jl | 2 +- test/Logging.jl | 29 +++++++++++++++++++++++++++++ test/runtests.jl | 2 ++ 4 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 test/Logging.jl diff --git a/src/evaluation/WorkspaceManager.jl b/src/evaluation/WorkspaceManager.jl index fc57e0ca2f..0514dd711d 100644 --- a/src/evaluation/WorkspaceManager.jl +++ b/src/evaluation/WorkspaceManager.jl @@ -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 diff --git a/src/runner/PlutoRunner.jl b/src/runner/PlutoRunner.jl index 24f5b183d7..425305c2c4 100644 --- a/src/runner/PlutoRunner.jl +++ b/src/runner/PlutoRunner.jl @@ -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], ) ) diff --git a/test/Logging.jl b/test/Logging.jl new file mode 100644 index 0000000000..9c816ca823 --- /dev/null +++ b/test/Logging.jl @@ -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 diff --git a/test/runtests.jl b/test/runtests.jl index 554de40c76..ba9ea13bff 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -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")