From 6ad63cd485ddc8d5d3f40494cb3aa98de650cab3 Mon Sep 17 00:00:00 2001 From: Alex Arslan Date: Fri, 30 Nov 2018 16:28:53 -0800 Subject: [PATCH] Make debugging macros insert branches on DEBUG_LEVEL --- src/debug.jl | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/src/debug.jl b/src/debug.jl index 8892a9c6a..160f1be23 100644 --- a/src/debug.jl +++ b/src/debug.jl @@ -3,23 +3,28 @@ taskid(t=current_task()) = string(hash(t) & 0xffff, base=16, pad=4) debug_header() = string("DEBUG: ", rpad(Dates.now(), 24), taskid(), " ") macro debug(n::Int, s) - DEBUG_LEVEL[] >= n ? :(println(debug_header(), $(esc(s)))) : - :() + quote + if DEBUG_LEVEL[] >= $n + println(debug_header(), $(esc(s))) + end + end end macro debugshow(n::Int, s) - DEBUG_LEVEL[] >= n ? :(println(debug_header(), - $(sprint(Base.show_unquoted, s)), " = ", - sprint(io->show(io, "text/plain", - begin value=$(esc(s)) end)))) : - :() - + quote + if DEBUG_LEVEL[] >= $n + println(debug_header(), $(sprint(Base.show_unquoted, s)), " = ", + sprint(io->show(io, "text/plain", begin value=$(esc(s)) end))) + end + end end macro debugshort(n::Int, s) - DEBUG_LEVEL[] >= n ? :(println(debug_header(), - sprintcompact($(esc(s))))) : - :() + quote + if DEBUG_LEVEL[] >= $n + println(debug_header(), sprintcompact($(esc(s)))) + end + end end sprintcompact(x) = sprint(show, x; context=:compact => true)