Allow emitting logs with customised metadata
I'm currently looking into better supporting logger in fiery (and by extension, the next invocation of plumber)
fiery has it's own log utility and I'd like for this to be able to use logger under the hood if the user wants to. However, to increase response time, logging is deferred to after the response has been sent, meaning that the time of the logging doesn't correspond to the time logger gets called.
Because of this it would be neat if logger exposed a way to overwrite the meta info that the layouts rely on
That's a fair request! 👍
On the other hand, for the actual use-case, did you consider using the async logging feature of logger (using mirai)? This way, you wouldn't need to defer logging in fiery as logger would handle that without messing around with overwriting metadata.
fiery supports a bunch of different loggers, not just logger, so it wouldn't really be possible. AFAICT, the change would be to move this line
https://github.com/daroczig/logger/blob/820ad5e7961800ce333031c94f5fc8a53c8a2644/R/logger-meta.R#L7
up into the function signature instead and have the same in log_level() as well. If you'd be ok with that I'd be happy to prepare a PR
Not all formatters are using logger_meta_env, and Sys.time() is currently hardcoded in a few of formatters as well (e.g. layout_simple). Maybe the layout fns should get a timestamp param default to Sys.time() and use it as-is or pass it down to logger_meta_env as needed .. and make that param publicly available via the logger functions.
BTW are we sure no other metadata will require a similar hack?
For my use case timestamp was the only missing, since the log context is already set-able with .logcall etc
For having it as an argument to layout_*() is your thinking that the argument will be passed from log_level() to the layout and then (potentially) to logger_meta_env() I'd be happy with that as well
Thank you, @thomasp85, I think that should work and I highly appreciate your help with this.