# Deactivate logging message locally

**URL:** <https://discourse.julialang.org/t/deactivate-logging-message-locally/64493>\
**Category:** General Usage\
**Tags:** logging\
**Created:** [July 12, 2021, 9:27am UTC](https://discourse.julialang.org/t/deactivate-logging-message-locally/64493 "2021-07-12T09:27:36Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![BambOoxX](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bambooxx/32/22179_2.png) [@BambOoxX](https://discourse.julialang.org/u/BambOoxX)\
**Post date:** [July 12, 2021, 9:27am UTC](https://discourse.julialang.org/t/deactivate-logging-message-locally/64493/1 "2021-07-12T09:27:36Z")

</div>

I currently have a struct whose constructor logs some messages when called, using `@info` and potentially `@warn`. This is useful to me when I need to check in the log what parameters I actually used in some of my computations.

However, in some other part, I need to initialize this structure but with default values, for which I do not need to see such logging message. Is there a way to achieve this ?

At the moment my strategy is the following:

```julia
let initialized_var
    with_logger(NullLogger()) do 
        initialized_var = init_var()
    end
end

```

The let is to ensure `initialized_var` is known outside of the `with_logger...` block. Is it possible to avoid this kind of structure ?

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [July 12, 2021, 1:15pm UTC](https://discourse.julialang.org/t/deactivate-logging-message-locally/64493/2 "2021-07-12T13:15:39Z")

</div>

You could define two constructor methods, eg something like

```julia
struct Foo
    x::Int
    function Foo(x::Int)
        @warn "constructing Foo" x
        new(x)
    end
    Foo() = new(42)
end
```

---

<div class="post-metadata">

**Author:** ![BambOoxX](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bambooxx/32/22179_2.png) [@BambOoxX](https://discourse.julialang.org/u/BambOoxX)\
**Post date:** [July 13, 2021, 1:36pm UTC](https://discourse.julialang.org/t/deactivate-logging-message-locally/64493/3 "2021-07-13T13:36:50Z")

</div>

Interesting, in some way, you mean to redefine the default constructor of the structure, right ?

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [July 13, 2021, 1:39pm UTC](https://discourse.julialang.org/t/deactivate-logging-message-locally/64493/4 "2021-07-13T13:39:07Z")

</div>

[https://docs.julialang.org/en/v1/manual/constructors/#man-inner-constructor-methods](https://docs.julialang.org/en/v1/manual/constructors/#man-inner-constructor-methods)
