# Call @show in logging macro

**URL:** <https://discourse.julialang.org/t/call-show-in-logging-macro/55313>\
**Category:** New to Julia\
**Tags:** question, macros, logging\
**Created:** [February 15, 2021, 12:21pm UTC](https://discourse.julialang.org/t/call-show-in-logging-macro/55313 "2021-02-15T12:21:33Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![AtsushiSakai](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/atsushisakai/32/6559_2.png) [@AtsushiSakai](https://discourse.julialang.org/u/AtsushiSakai)\
**Post date:** [February 15, 2021, 12:21pm UTC](https://discourse.julialang.org/t/call-show-in-logging-macro/55313/1 "2021-02-15T12:21:33Z")

</div>

Does anyone know how to call @show in logging macro, ex @info?

I tried:

> julia\> using Logging
> 
> julia\> @info “hi”  
> [ Info: hi
> 
> julia\> message = “hi”  
> “hi”
> 
> julia\> @info message  
> [ Info: hi
> 
> julia\> @info @show message  
> message = “hi”  
> [ Info: hi

But, I want to get this using both @show and @info:

> [ info: message = “hi”

---

<div class="post-metadata">

**Author:** ![pfitzseb](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pfitzseb/32/45566_2.png) [@pfitzseb](https://discourse.julialang.org/u/pfitzseb)\
**Post date:** [February 15, 2021, 12:30pm UTC](https://discourse.julialang.org/t/call-show-in-logging-macro/55313/2 "2021-02-15T12:30:48Z")

</div>

If you give some string as the first arg to `@info` you’ll end up with

```julia
julia> @info "" message
┌ Info: 
└ message = "hi"

```

which might be what you’re looking for?

---

<div class="post-metadata">

**Author:** ![AtsushiSakai](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/atsushisakai/32/6559_2.png) [@AtsushiSakai](https://discourse.julialang.org/u/AtsushiSakai)\
**Post date:** [February 15, 2021, 12:41pm UTC](https://discourse.julialang.org/t/call-show-in-logging-macro/55313/3 "2021-02-15T12:41:08Z")

</div>

Thank you!!. It works for me.  
But it is perfect if the output becomes just one line, not two line…

---

<div class="post-metadata">

**Author:** ![dmolina](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dmolina/32/5246_2.png) [@dmolina](https://discourse.julialang.org/u/dmolina)\
**Post date:** [February 15, 2021, 12:51pm UTC](https://discourse.julialang.org/t/call-show-in-logging-macro/55313/4 "2021-02-15T12:51:22Z")

</div>

The option of @pfitzseb is nice.  
Another option is to define your own macro:

```julia
macro infoshow(expr) 
      quote 
              @info string($(QuoteNode(expr)), " = ", $expr) 
      end 
end

```

Then, you can use it directly:

```julia
julia> @infoshow message
[ Info: message= hola

```

**Edit:** In that case, you are limited to only use one variable at the same time, I do not know enough of macros to make it as good as original `@show` macro.

---

<div class="post-metadata">

**Author:** ![Skoffer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/skoffer/32/378_2.png) [@Skoffer](https://discourse.julialang.org/u/Skoffer)\
**Post date:** [February 15, 2021, 1:06pm UTC](https://discourse.julialang.org/t/call-show-in-logging-macro/55313/5 "2021-02-15T13:06:37Z")

</div>

You can use `OneLineTransformerLogger` from [LoggingFacilities.jl](https://github.com/tk3369/LoggingFacilities.jl).

---

<div class="post-metadata">

**Author:** ![AtsushiSakai](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/atsushisakai/32/6559_2.png) [@AtsushiSakai](https://discourse.julialang.org/u/AtsushiSakai)\
**Post date:** [February 17, 2021, 11:59am UTC](https://discourse.julialang.org/t/call-show-in-logging-macro/55313/6 "2021-02-17T11:59:15Z")

</div>

Thanks all. All answers are great. I dare say that @pfitzseb 's answer was the one I was looking for the most. So marked it as Solution.
