Guard log_printf in LOG macros with a log level check

So that the format arguments will only be evaluated if the log is
enabled by the log level. Allow us to add more expensive logs without
impact performance when they are not enabled.

Signed-off-by: Yuxuan Shui <yshuiv7@gmail.com>
This commit is contained in:
Yuxuan Shui
2018-12-20 02:34:45 +00:00
parent fc57c7b55b
commit 185c0ce97c
2 changed files with 16 additions and 1 deletions

View File

@@ -98,6 +98,10 @@ void log_set_level(struct log *l, int level) {
l->log_level = level;
}
enum log_level log_get_level(const struct log *l) {
return l->log_level;
}
attr_printf(4, 5) void log_printf(struct log *l, int level, const char *func,
const char *fmt, ...) {
assert(level <= LOG_LEVEL_FATAL && level >= 0);