blah/src/blah_common.cpp

58 lines
1011 B
C++
Raw Normal View History

#include <blah_common.h>
#include <blah_app.h>
2020-08-26 15:38:01 +08:00
using namespace Blah;
void Log::info(const char* format, ...)
2020-08-26 15:38:01 +08:00
{
char msg[max_length];
2020-08-26 15:38:01 +08:00
va_list ap;
va_start(ap, format);
vsnprintf(msg, sizeof(char) * max_length, format, ap);
2020-08-26 15:38:01 +08:00
va_end(ap);
2022-02-13 15:14:35 +08:00
if (App::is_running() && App::config().on_log)
2020-08-26 15:38:01 +08:00
{
App::config().on_log(msg, Category::Info);
2020-08-26 15:38:01 +08:00
}
else
{
printf("%s\n", msg);
}
}
void Log::warn(const char* format, ...)
{
char msg[max_length];
2020-08-26 15:38:01 +08:00
va_list ap;
va_start(ap, format);
vsnprintf(msg, sizeof(char) * max_length, format, ap);
2020-08-26 15:38:01 +08:00
va_end(ap);
2022-02-13 15:14:35 +08:00
if (App::is_running() && App::config().on_log)
2020-08-26 15:38:01 +08:00
{
App::config().on_log(msg, Category::Warning);
2020-08-26 15:38:01 +08:00
}
else
{
printf("WARN: %s\n", msg);
2020-08-26 15:38:01 +08:00
}
}
void Log::error(const char* format, ...)
{
char msg[max_length];
2020-08-26 15:38:01 +08:00
va_list ap;
va_start(ap, format);
vsnprintf(msg, sizeof(char) * max_length, format, ap);
2020-08-26 15:38:01 +08:00
va_end(ap);
2022-02-13 15:14:35 +08:00
if (App::is_running() && App::config().on_log)
2020-08-26 15:38:01 +08:00
{
App::config().on_log(msg, Category::Error);
2020-08-26 15:38:01 +08:00
}
else
{
printf("ERROR: %s\n", msg);
2020-08-26 15:38:01 +08:00
}
}