Fix formatting long as %d in util/log.cpp

Changed log level type from long to int, since value is
expected to be a small integer in range [0-3].

Since codebase requires C++17 also replaced strtol with
std::from_chars(), which will parse string as int, and skip updating
the defaut value if VULKAN_WSI_DEBUG_LEVEL env var does not represent
int.

Signed-off-by: Daniel Levin <daniel.levin@amd.com>
This commit is contained in:
Daniel Levin 2023-10-13 04:31:34 -07:00 committed by Rosen Zhelev
parent 188ffe6a26
commit d3e284cd7e
2 changed files with 6 additions and 5 deletions

View file

@ -24,6 +24,7 @@
#include "log.hpp"
#include <iostream>
#include <charconv>
#include <cstdarg>
#include <cstdio>
#include <cstdlib>
@ -38,16 +39,16 @@ namespace util
/**
* @brief check if a log level is enabled, and print it
*/
static bool check_and_print_log_level(long level)
static bool check_and_print_log_level(int level)
{
struct log_state
{
long level = WSI_DEFAULT_LOG_LEVEL;
int level = WSI_DEFAULT_LOG_LEVEL;
log_state()
{
if (const char *env = std::getenv("VULKAN_WSI_DEBUG_LEVEL"))
{
level = strtol(env, nullptr, 0);
std::from_chars(env, env + std::strlen(env), level);
}
}
};
@ -78,7 +79,7 @@ static bool check_and_print_log_level(long level)
return result;
}
void wsi_log_message(long level, const char *file, int line, const char *format, ...)
void wsi_log_message(int level, const char *file, int line, const char *format, ...)
{
if (check_and_print_log_level(level))
{

View file

@ -45,7 +45,7 @@ namespace util
* @param[in] format A C-style formatting string.
*/
void wsi_log_message(long level, const char *file, int line, const char *format, ...)
void wsi_log_message(int level, const char *file, int line, const char *format, ...)
#ifdef __GNUC__
__attribute__((format(printf, 4, 5)))
#endif