LoggingExtras.jl -> Get STRING from LOGGING MACRO

How can I get string message from log macro?

@info "My message"

I used FormatLogger so output looks like:

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.

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

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.

2 Likes

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.

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

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

thank you