# Term.jl / logging / sending messages to multiple locations

**URL:** https://discourse.julialang.org/t/term-jl-logging-sending-messages-to-multiple-locations/84841
**Category:** General Usage
**Tags:** logging, termjl
**Created:** [July 26, 2022, 6:25pm UTC](https://discourse.julialang.org/t/term-jl-logging-sending-messages-to-multiple-locations/84841 "2022-07-26T18:25:38Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![j\_u](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/j_u/32/219081_2.png) [@j\_u](https://discourse.julialang.org/u/j_u)
#### Post date: [July 26, 2022, 6:25pm UTC](https://discourse.julialang.org/t/term-jl-logging-sending-messages-to-multiple-locations/84841/1 "2022-07-26T18:25:38Z")

</div>

I’d like to ask if sending logging messages both to terminal and to a file is supported by `Term.jl` [[Logging · Term.jl](https://fedeclaudi.github.io/Term.jl/stable/adv/logging/)]. I read in `JuliaLogging` documentation that `Logging` together with` LoggingExtras` is supporting such option (for more info on this topic pls see: [[Send messages to multiple locations · JuliaLogging](https://julialogging.github.io/how-to/tee/#Send-messages-to-multiple-locations)]). Edit: Pinging @FedeClaudi, should there be no info here, I will allow myself to ask at GitHub.

---

<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: [July 27, 2022, 10:48pm UTC](https://discourse.julialang.org/t/term-jl-logging-sending-messages-to-multiple-locations/84841/2 "2022-07-27T22:48:51Z")

</div>

```julia
julia> using Term, LoggingExtras

julia> global_logger(
           TeeLogger(
               Term.TermLogger(Term.TERM_THEME[]),
               FileLogger("julia.log"),
           ),
       );

julia> @info "hello info"
@Info (Main): hello info
  ╰────────────────────────────────────────────────
                      Thu, 28 Jul 2022 00:49:09

julia> @warn "hello warn"
@Warn (Main): hello warn
  ╰────────────────────────────────────────────────
                      Thu, 28 Jul 2022 00:49:11

shell> cat julia.log
┌ Info: hello info
└ @ Main REPL[20]:1
┌ Warning: hello warn
└ @ Main REPL[21]:1

```

Edit: I submitted [this patch](https://github.com/FedeClaudi/Term.jl/pull/136) to make it a bit easier to construct a `TermLogger`.

---

<div class="post-metadata">

### Author: ![j\_u](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/j_u/32/219081_2.png) [@j\_u](https://discourse.julialang.org/u/j_u)
#### Post date: [July 27, 2022, 11:37pm UTC](https://discourse.julialang.org/t/term-jl-logging-sending-messages-to-multiple-locations/84841/3 "2022-07-27T23:37:00Z")

</div>

Thanks a lot @fredrikekre. Having the opportunity, I am wondering, is there any recommended way to log the output of functions / commands that return “nothing” with the use of `TeeLogger`?. Two examples of such functions / commands: `Pkg.status()` and `Base.Sys.cpu_summary()`. To log output of such commands / functions I came up (based on Logging documentation) with the following idea [[link](https://discourse.julialang.org/t/a-string-pkg-status-nothing-how-to-get-and-save-pkg-status/24571/5)], however, I am not quite sure how to implement it with `TeeLogger`. Is it possible at all? What I am trying to achieve is to reduce `println` commands in my code and exchange them with logging.

---

<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: [July 28, 2022, 7:37am UTC](https://discourse.julialang.org/t/term-jl-logging-sending-messages-to-multiple-locations/84841/4 "2022-07-28T07:37:01Z")

</div>

Not directly, because those functions don’t use the logging system, they simply print to stdout. You can of course create the string and log that:

```julia
julia> using Pkg

julia> str = sprint(io -> Pkg.status(; io = io));

julia> @info str
┌ Info: Status `/tmp/tmp.oJfx8Aw4So/Project.toml`
└ [7876af07] Example v0.5.3

```

---

<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: [July 28, 2022, 11:00am UTC](https://discourse.julialang.org/t/term-jl-logging-sending-messages-to-multiple-locations/84841/5 "2022-07-28T11:00:43Z")

</div>

Thanks for the PR and for answering the question ( I didn’t know the answer as well!) @fredrikekre

I will link to this discussion in the Term docs for future reference.

---

<div class="post-metadata">

### Author: ![j\_u](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/j_u/32/219081_2.png) [@j\_u](https://discourse.julialang.org/u/j_u)
#### Post date: [July 29, 2022, 12:23am UTC](https://discourse.julialang.org/t/term-jl-logging-sending-messages-to-multiple-locations/84841/6 "2022-07-29T00:23:00Z")

</div>

Thanks @fredrikekre for detailed info! I just came by one more case that is misterious to me: `Hwloc.topology_info()`. It also returns `nothing`, however, if trying:

`str = sprint(io -> Hwloc.topology_info(; io = io));`

I am receiving:

```julia
ERROR: MethodError: no method matching topology_info(; io=IOBuffer(data=UInt8[...], readable=true, writable=true, seekable=true, append=false, size=0, maxsize=Inf, ptr=1, mark=-1))
Closest candidates are:
  topology_info() at ~/.julia/packages/Hwloc/HorQV/src/highlevel_api.jl:76 got unsupported keyword argument "io"

```

Is there any chance you may have an advice on this as well?

@FedeClaudi, great package `Term.jl`!

---

<div class="post-metadata">

### Author: ![j\_u](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/j_u/32/219081_2.png) [@j\_u](https://discourse.julialang.org/u/j_u)
#### Post date: [July 30, 2022, 10:48am UTC](https://discourse.julialang.org/t/term-jl-logging-sending-messages-to-multiple-locations/84841/7 "2022-07-30T10:48:57Z")

</div>

I will try to investigate it further and when / if I come with a solution to this particular case I will post it here. Many thanks to both of you for the advice and for great packages.

---

<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: [July 30, 2022, 12:07pm UTC](https://discourse.julialang.org/t/term-jl-logging-sending-messages-to-multiple-locations/84841/8 "2022-07-30T12:07:06Z")

</div>

You can of course only pass the `IO` if the method supports that.

`Hwloc.topology_info()` doesn’t support it, but I am sure a contribution of `topology_info(io::IO=stdout)` would be welcome.

---

<div class="post-metadata">

### Author: ![j\_u](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/j_u/32/219081_2.png) [@j\_u](https://discourse.julialang.org/u/j_u)
#### Post date: [July 30, 2022, 11:26pm UTC](https://discourse.julialang.org/t/term-jl-logging-sending-messages-to-multiple-locations/84841/9 "2022-07-30T23:26:30Z")

</div>

> [@fredrikekre](#):
>
> You can of course only pass the `IO` if the method supports that.

Aha! I’m relatively new to coding, I’ve written only a few hundred / thousands lines, mostly data analysis and visualizations. I’ve been using modules, structs, functions rather in their basic forms. I’ll read more on the topic of methods and I’ll try to implement your advice in the near future. Thanks again.
