Semantic or structured logging


@Chris_Foster It seems the new logging framework / MicroLogging supports structured/semantic logging by allowing additional key/value pairs in addition to a message. Is it possible to only give a string interpolation expression or a string concatenation and let the backend capture the values in the expression?

Similar to how logging is done in e.g. ASP.NET Core:


At the moment you’d have to do this by hand by using the key value pairs if you want to capture the values which go into the message:

@info "Starting iteration $i" i

The philosophy here is that the message is for human consumption, while the key value pairs are for holding structured data without needing to convert it to text. In general I think you want two different things for those.

I did consider destructuring the expression and storing the values which went into it, but I’m not sure it’s easy or sensible to do this in general because it can sometimes be useful for the expression to contain logic in addition to being a simple template. An example from Base.Pkg:

        @info begin
            "Package $p was set to version $v, but a higher version $(vers[end]) exists.\n" *
            if isfixed
                "The package is fixed. You can try using `\"$p\")` to update it."
            elseif blocking_reqs
                "The update is prevented by explicit requirements constraints. Edit your REQUIRE file to change this."
            elseif !isempty(blocking_parents)
                string("To install the latest version, you could try updating these packages as well: ", join(blocking_parents, ", ", " and "), ".")
                "To install the latest version, you could try doing a full update with `Pkg.update()`."