Open ssfrr opened 1 year ago
For now I just defined
struct RawStr
x::String
end
Base.show(io::IO, m::MIME"text/plain", s::RawStr) = show(io, m, s.x)
and I can do @info RawStr("writing to $path")
There should really be a way to disable this IMHO as it breaks any multiline messages, making it unsuitable as a drop-in default logger or in combination with other loggers that don't do markdown
I just had exactly the same problem. The fact that log messages are interpreted as Markdown by default surprised me, especially since if I actually wanted that I could just do:
using Markdown
@info md"Some _emphasized_ text."
Output: Some emphasized text.
Regarding the specific issue of interpolating paths: I usually quote values inside text output, especially if they are text themselves, e.g. in single quotes to signify which part of the message is variable. For TerminalLogger
, quoting with backticks instead bypasses the issue:
@info "Some `path_with_underscores`."
Output: Some path_with_underscores
.
This is not perfect because TerminalLogger
just drops all styling, including the quotations, when the output stream does not support displaying it (like when redirecting standard error into a file) -- instead it should arguably output the source Markdown instead.
In my opinion, Markdown formatting should be opt-in.
I’m logging an interpolated string, but underlines in the path are being interpreted as markdown by the logging:
(you can’t see it, but
path
is underlined in thesomepathfoo
in the REPL).My first idea was to add escapes to the
_
:This isn't super great because folks who are using the default
ConsoleLogger
will see the extra escape characters.The other option would be to define a custom type that's not an
AbstractString
and defines the rightshow
method, but this also seems clunky.Is there an easier way to prevent markdown parsing?