# LoggingExtras.jl -\> Get STRING from LOGGING MACRO

**URL:** <https://discourse.julialang.org/t/loggingextras-jl-get-string-from-logging-macro/64731>\
**Category:** General Usage\
**Created:** [July 16, 2021, 6:47am UTC](https://discourse.julialang.org/t/loggingextras-jl-get-string-from-logging-macro/64731 "2021-07-16T06:47:33Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Michal](https://avatars.discourse-cdn.com/v4/letter/m/34f0e0/32.png) [@Michal](https://discourse.julialang.org/u/Michal)\
**Post date:** [July 16, 2021, 6:47am UTC](https://discourse.julialang.org/t/loggingextras-jl-get-string-from-logging-macro/64731/1 "2021-07-16T06:47:33Z")

</div>

How can I get string message from log macro?

```julia
@info "My message"

```

I used FormatLogger so output looks like:

```julia
2021-07-16 --- My message --- INFO --- Main.module

```

I would liek to get this full message as a string. How is it possible?  
str = @info “My message”

@fredrikekre so sorry for interrupting you so often, I think you will know help me with this issue.

---

<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 16, 2021, 8:25am UTC](https://discourse.julialang.org/t/loggingextras-jl-get-string-from-logging-macro/64731/2 "2021-07-16T08:25:32Z")

</div>

I don’t.

What do you need the string for and why are you using the logging system for it? You could just construct the string directly like

```julia
str = "$(date) --- message here --- INFO --- $(@ __MODULE__ )"

```

for example.

* * *

As an aside, please don’t ping users directly (at least not me) in threads where they haven’t participated. Just state your question and anyone that knows the answer can help. I am happy to help when I can, but there are many users on the forum that can help.

---

<div class="post-metadata">

**Author:** ![Michal](https://avatars.discourse-cdn.com/v4/letter/m/34f0e0/32.png) [@Michal](https://discourse.julialang.org/u/Michal)\
**Post date:** [July 16, 2021, 9:35am UTC](https://discourse.julialang.org/t/loggingextras-jl-get-string-from-logging-macro/64731/3 "2021-07-16T09:35:43Z")

</div>

Yes, I understand. Sorry for that.

1. My logger construct strings from endpoint name and user ID. I just want to get this string from logger.
2. I want to create UT, where I will check my format of message on output.

---

<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 16, 2021, 10:01am UTC](https://discourse.julialang.org/t/loggingextras-jl-get-string-from-logging-macro/64731/4 "2021-07-16T10:01:57Z")

</div>

For testing, just put an `IOBuffer` as the log stream and then read the result from that. Pseudocode:

```julia
io = IOBuffer()
logger = FormatLogger(format_func, io)
with_logger(logger)
    # do stuff that generate log messages
end
str = String(take!(io))

```

---

<div class="post-metadata">

**Author:** ![Michal](https://avatars.discourse-cdn.com/v4/letter/m/34f0e0/32.png) [@Michal](https://discourse.julialang.org/u/Michal)\
**Post date:** [July 16, 2021, 10:23am UTC](https://discourse.julialang.org/t/loggingextras-jl-get-string-from-logging-macro/64731/5 "2021-07-16T10:23:59Z")

</div>

thank you
