# Debug checks without output

**URL:** <https://discourse.julialang.org/t/debug-checks-without-output/90458>\
**Category:** General Usage\
**Created:** [November 18, 2022, 3:36pm UTC](https://discourse.julialang.org/t/debug-checks-without-output/90458 "2022-11-18T15:36:13Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![andrey2185](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/andrey2185/32/9889_2.png) [@andrey2185](https://discourse.julialang.org/u/andrey2185)\
**Post date:** [November 18, 2022, 3:36pm UTC](https://discourse.julialang.org/t/debug-checks-without-output/90458/1 "2022-11-18T15:36:13Z")

</div>

hello, is it correct way to use a large number of checks in the code without output, and then turn them off at once?

```julia
const USE_DEBUG_CODE_BLOCKS = true

macro debug_code_block(expr)
    USE_DEBUG_CODE_BLOCKS || return nothing
    return expr
end

@debug_code_block begin
    1 != 1 && throw("ooops!")
end

```

or how to disable the output for @debug but have the checks run?

---

<div class="post-metadata">

**Author:** ![fredrikekre](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fredrikekre/32/1688_2.png) [@fredrikekre](https://discourse.julialang.org/u/fredrikekre)\
**Post date:** [November 18, 2022, 3:50pm UTC](https://discourse.julialang.org/t/debug-checks-without-output/90458/2 "2022-11-18T15:50:53Z")

</div>

If you change the macro to:

```julia
macro debug_code_block(expr)
    USE_DEBUG_CODE_BLOCKS || return nothing
    return :($(esc(expr)))
end

```

it works:

```julia
julia> const USE_DEBUG_CODE_BLOCKS = true;

julia> macro debug_code_block(expr)
           USE_DEBUG_CODE_BLOCKS || return nothing
           return :($(esc(expr)))
       end;

julia> @debug_code_block begin
           1 != 1 || throw("ooops!")
       end
ERROR: "ooops!"
Stacktrace:
 [1] top-level scope
   @ REPL[3]:2

```

```julia
julia> const USE_DEBUG_CODE_BLOCKS = false;

julia> macro debug_code_block(expr)
           USE_DEBUG_CODE_BLOCKS || return nothing
           return :($(esc(expr)))
       end;

julia> @debug_code_block begin
           1 != 1 || throw("ooops!")
       end

julia>

```

Note that you need to restart Julia when toggling like this.

---

<div class="post-metadata">

**Author:** ![andrey2185](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/andrey2185/32/9889_2.png) [@andrey2185](https://discourse.julialang.org/u/andrey2185)\
**Post date:** [November 18, 2022, 3:54pm UTC](https://discourse.julialang.org/t/debug-checks-without-output/90458/3 "2022-11-18T15:54:46Z")

</div>

but it is a correct way ? or use @debug or something else is better ?

---

<div class="post-metadata">

**Author:** ![andrey2185](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/andrey2185/32/9889_2.png) [@andrey2185](https://discourse.julialang.org/u/andrey2185)\
**Post date:** [November 18, 2022, 4:00pm UTC](https://discourse.julialang.org/t/debug-checks-without-output/90458/4 "2022-11-18T16:00:25Z")

</div>

I just don’t want to destroy the console with millions of debug messages

---

<div class="post-metadata">

**Author:** ![fredrikekre](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fredrikekre/32/1688_2.png) [@fredrikekre](https://discourse.julialang.org/u/fredrikekre)\
**Post date:** [November 18, 2022, 4:01pm UTC](https://discourse.julialang.org/t/debug-checks-without-output/90458/5 "2022-11-18T16:01:16Z")

</div>

It is _a_ way, and I don’t see anything wrong with it. I use it in some packages, e.g. in [Ferrite.jl](https://github.com/Ferrite-FEM/Ferrite.jl/blob/c90c188bb1dab0ac03f30b0b173db18880ddddbc/src/utils.jl#L1-L36).

Note that [`@debug`](https://docs.julialang.org/en/v1/stdlib/Logging/#Logging.@logmsg) is for log messages, and [`@assert`](https://docs.julialang.org/en/v1/base/base/#Base.@assert) is currently not toggleable (see [JuliaLang/julia#37874](https://github.com/JuliaLang/julia/pull/37874) for some work towards making it so).

---

<div class="post-metadata">

**Author:** ![andrey2185](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/andrey2185/32/9889_2.png) [@andrey2185](https://discourse.julialang.org/u/andrey2185)\
**Post date:** [November 18, 2022, 4:02pm UTC](https://discourse.julialang.org/t/debug-checks-without-output/90458/6 "2022-11-18T16:02:15Z")

</div>

thank you
