3 ms·
TLDR: logger.log( logfmtxx::level::error, "internal server error", logfmtxx::field{"http.method", "GET"}, logfmtxx::field{"http.path", "/"}, logfmtxx
by pshirshov 3y ago
TLDR:
logger.log(
logfmtxx::level::error,
"internal server error",
logfmtxx::field{"http.method", "GET"},
logfmtxx::field{"http.path", "/"},
logfmtxx::field{"http.status", 500}
);
This is a very dated approach to structural logging.
Modern implementations are effortless: https://izumi.7mind.io/logstage/index.html https://izumi.7mind.io/logstage/index.html
- linkdd 3y agoHow is it dated? That's how the Python logging library works, that's how Go's `slog` package works, that's how most of Rust's structured logging crates works. I guess the definition of "effortless" varies from people to people, I find this "no hard setup required" way to be effortless.
- gpderetta 3y agoIt is a bit verbose. Could you allow a syntax like: logger.log_error("internal server error", {{"http.method", "GET"}, {"http.path", "/"}, {"http.status", 500}} );
- linkdd 3y agodebug/info/warn/error methods are coming. For the latter, since I use a pack expansion ( `...` ) of `field<T>`, maybe it is already possible to omit the type name. I shall put that in a test case and update the README :) Thank you for the feedback.
- gpderetta 3y agoNot sure you can do it with a pack expansion. You can do it by taking an initializer_list<logfmtxx::field> though. edit: example: https://gcc.godbolt.org/z/dK7Tq6hja https://gcc.godbolt.org/z/dK7Tq6hja