# Logging: symbol evaluation under the hood

**URL:** <https://discourse.julialang.org/t/logging-symbol-evaluation-under-the-hood/77399>\
**Category:** General Usage\
**Tags:** question, logging\
**Created:** [March 4, 2022, 1:34pm UTC](https://discourse.julialang.org/t/logging-symbol-evaluation-under-the-hood/77399 "2022-03-04T13:34:59Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![FedeClaudi](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fedeclaudi/32/33490_2.png) [@FedeClaudi](https://discourse.julialang.org/u/FedeClaudi)\
**Post date:** [March 4, 2022, 1:34pm UTC](https://discourse.julialang.org/t/logging-symbol-evaluation-under-the-hood/77399/1 "2022-03-04T13:34:59Z")

</div>

Hey everyone,

As mentioned [in other posts](https://discourse.julialang.org/t/intercepting-error-messages-how/77189/4), I’m working on a package called Term.jl that does a bunch of pretty terminal stuff like printing formatted error messages:

 ![image](https://global.discourse-cdn.com/julialang/original/3X/1/b/1befb1194654b3f67e638ec66059b7c7bd7d9bf0.png)

One of the features I’d like to add is formatted logging. Similar to the built-in logging system but with fancier formatting. Such that:

```julia
function foo()
    x = 1
    @info "this sis sodifsdfnso" 1+1 x 2x
    @tinfo "this sis sodifsdfnso" 1+1 x 2x
end

```

which would normally give  
 ![image](https://global.discourse-cdn.com/julialang/original/3X/7/9/79b7ae1b5726ff94b477022d9c09c78d8d59a506.png)

would give something with a bit more color:  
 ![image](https://global.discourse-cdn.com/julialang/original/3X/7/1/7194d0250f59fec4bc64fee63ab2f65099f93090.png)

However I can’t quite figure out how the logging code in `Base` evaluates symbols and expressions to produce the logging message. E.g if while handling that log message I try to evaluate `2x` I get an error saying that `x` is not defined (as it isn’t within the `@tinfo` macro). I’ve looked in details at [julia/logging.jl](https://github.com/JuliaLang/julia/blob/master/base/logging.jl#L323), but the code is fairly dense and I can’t quite figure out how they get the values associated with variables/symbols passed to the logging macros. I suspect that it’s handled by [`log_msgcode`](https://github.com/JuliaLang/julia/blob/2f67b51c70280cf7f0f2da5de2e7769da0d49869/base/logging.jl#L323), but I can’t figure out what that function does exactly.

Any help would be appreciated!

---

<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:** [March 4, 2022, 1:59pm UTC](https://discourse.julialang.org/t/logging-symbol-evaluation-under-the-hood/77399/2 "2022-03-04T13:59:39Z")

</div>

Have you seen [https://julialogging.github.io/](https://julialogging.github.io/)? I believe that should help you with all your questions.

---

<div class="post-metadata">

**Author:** ![FedeClaudi](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fedeclaudi/32/33490_2.png) [@FedeClaudi](https://discourse.julialang.org/u/FedeClaudi)\
**Post date:** [March 4, 2022, 2:01pm UTC](https://discourse.julialang.org/t/logging-symbol-evaluation-under-the-hood/77399/3 "2022-03-04T14:01:11Z")

</div>

I have not! That seems to be very useful, I’ll need to dig in and see how to combine it with styling done by Term.jl.

Thank you 🙏

---

<div class="post-metadata">

**Author:** ![FedeClaudi](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fedeclaudi/32/33490_2.png) [@FedeClaudi](https://discourse.julialang.org/u/FedeClaudi)\
**Post date:** [March 5, 2022, 10:46am UTC](https://discourse.julialang.org/t/logging-symbol-evaluation-under-the-hood/77399/4 "2022-03-05T10:46:22Z")

</div>

Logging.jl had all I needed, thank you @fredrikekre

![image](https://global.discourse-cdn.com/julialang/original/3X/d/2/d2fd9c9dd3598701484a75f499455fcc707a8bae.png)

---

<div class="post-metadata">

**Author:** ![FedeClaudi](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fedeclaudi/32/33490_2.png) [@FedeClaudi](https://discourse.julialang.org/u/FedeClaudi)\
**Post date:** [March 5, 2022, 6:56pm UTC](https://discourse.julialang.org/t/logging-symbol-evaluation-under-the-hood/77399/5 "2022-03-05T18:56:38Z")

</div>

@fredrikekre do you know if there’s something similar for [error messages](https://discourse.julialang.org/t/intercepting-error-messages-how/77189/6)?

Something that takes care of all the hard work and allows me to just define some code to style the error messages?
