-
Notifications
You must be signed in to change notification settings - Fork 4
added convience functions #15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
realized logger has capital function names. Do you want me to change to |
Yes please, Google style FTW |
Log(LogLevel::kERROR, std::move(str)); | ||
} | ||
inline void Fatal(std::string&& str) { | ||
Log(LogLevel::kFATAL, std::move(str)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There isn't really a benefit to these rvalue overloads when the underlying function does not swallow up that object and thus can only really use it as a const-ref.
if (!_enabled || LogLevel::kVERBOSE_DEBUG < min_level_) { | ||
return; | ||
} | ||
Log(LogLevel::kVERBOSE_DEBUG, fmt::format(fmt, std::forward<Ts>(args)...)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this file is going to be using fmt
, it needs to include the relevant headers and dependency in the bazel target.
if (!_enabled || LogLevel::kDBG < min_level_) { | ||
return; | ||
} | ||
Log(LogLevel::DBG, fmt::format(fmt, std::forward<Ts>(args)...)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a weird that when the user calls Log(lvl, str, a, b, c)
(i.e., the vararg version) it gets formatted, under-the-hood, with the "printf" formatting, but then, if they call Info(str, a, b, c)
it gets formatted with the python-style fmt specifications.
N.B.: I much prefer the fmt version, but I think it needs to be consistent.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the idea of this. In fact, in my own company's logging library, we have similar perfect forwarding of the fmt+args down to the logging functions to present the user with a similarly convenient syntax.
One big design feature that I would very much recommend (and might be able to provide the code for), is to perfectly forward all the way down to the implementation of Log / VLog functions because that will allow for logging functions that do not require any dynamic memory allocation, which is very handy in real-time and signal handler contexts, and quite easy to do with the fmt library. I did this very easily, and I can remove malloc/free in some contexts and still log messages to stdout/stderr.
But, this will require rewriting Log/VLog completely. So, maybe something for @dallison to think about.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thats a good call. Will update. Thanks
Added convience function which avoid str format until after log has been checked.
goes to