poac
poac copied to clipboard
Use fmt::format for loggers
https://github.com/poac-dev/poac/blob/23471b6c352809dff0d0655cbb47586e1c8e3358/src/Logger.hpp
For error
, warn
, info
, debug
, and trace
, we'd like to use fmt::format
style formatting instead of std::ostream
(internal implementation details). For example, the following usage is not that clear:
https://github.com/poac-dev/poac/blob/23471b6c352809dff0d0655cbb47586e1c8e3358/src/main.cc#L94-L96
We may want to do like this instead:
logger::error(
"'poac {}' failed with exit code `{}`", *itr, exitCode
);
We can use fmt::format
for arguments to these loggers and we do, but the new interface will be clearer:
https://github.com/poac-dev/poac/blob/23471b6c352809dff0d0655cbb47586e1c8e3358/src/Cmd/Build.cc#L52-L58
logger::info
can be:
logger::info(
"Compiling", "{} v{} ({})", packageName,
getPackageVersion().toString(),
getProjectBasePath().string()
);
Theoretically, error
, warn
, debug
, and trace
's function arguments would be like:
(fmt::format_string<T...> fmt, T&&... args)
And info
has:
(std::string_view header, fmt::format_string<T...> fmt, T&&... args)
Note that the actual implementation may be different as to conform to the current implementation style.