# Set printing debug messages programmatically

**URL:** <https://discourse.julialang.org/t/set-printing-debug-messages-programmatically/13875>\
**Category:** General Usage\
**Created:** [August 22, 2018, 9:34am UTC](https://discourse.julialang.org/t/set-printing-debug-messages-programmatically/13875 "2018-08-22T09:34:21Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ulysses](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ulysses/32/665_2.png) [@ulysses](https://discourse.julialang.org/u/ulysses)\
**Post date:** [August 22, 2018, 9:34am UTC](https://discourse.julialang.org/t/set-printing-debug-messages-programmatically/13875/1 "2018-08-22T09:34:21Z")

</div>

Is there a way to turn on `@debug`-printing programmatically instead of using env variable `JULIA_DEBUG`? My attempt was

```julia
using Base.CoreLogging: disable_logging, BelowMinLevel
disable_logging(BelowMinLevel)
@debug("hi")

```

but with no success.

---

<div class="post-metadata">

**Author:** ![adamslc](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/adamslc/32/3452_2.png) [@adamslc](https://discourse.julialang.org/u/adamslc)\
**Post date:** [August 22, 2018, 3:11pm UTC](https://discourse.julialang.org/t/set-printing-debug-messages-programmatically/13875/2 "2018-08-22T15:11:49Z")

</div>

If you take a look at the [Logging docs](https://docs.julialang.org/en/stable/stdlib/Logging/#Early-filtering-and-message-handling-1), you’ll see that there is a whole sequence of tests that occur before a log record is generated.

Your code has updated the first of the three checks, but then the default logger (a `ConsoleLogger`) is rejecting the debug record. Presumably, when you start julia with an env variable present, the `ConsoleLogger` adjusts its minimum log level.

To make it work, you should replace the default logger:

```julia
using Logging: disable_logging, global_logger, ConsoleLogger, BelowMinLevel

disable_logging(BelowMinLevel)
global_logger(ConsoleLogger(stderr, BelowMinLevel))

@debug "hi"

```
