2021-01-01 05:43:23 +08:00
|
|
|
#include <blah/core/log.h>
|
|
|
|
#include <blah/core/app.h>
|
2020-08-26 15:38:01 +08:00
|
|
|
#include <stdarg.h> // for logging methods
|
|
|
|
#include <stdio.h> // for sprintf
|
|
|
|
|
|
|
|
using namespace Blah;
|
|
|
|
|
|
|
|
void Log::print(const char* format, ...)
|
|
|
|
{
|
2020-08-28 10:44:03 +08:00
|
|
|
char msg[BLAH_MESSAGE];
|
2020-08-26 15:38:01 +08:00
|
|
|
va_list ap;
|
|
|
|
va_start(ap, format);
|
2020-08-28 10:44:03 +08:00
|
|
|
vsnprintf(msg, sizeof(char) * BLAH_MESSAGE, format, ap);
|
2020-08-26 15:38:01 +08:00
|
|
|
va_end(ap);
|
|
|
|
|
|
|
|
if (App::is_running() && App::config()->on_info != nullptr)
|
|
|
|
{
|
|
|
|
App::config()->on_info(msg);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
printf("%s\n", msg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Log::warn(const char* format, ...)
|
|
|
|
{
|
2020-08-28 10:44:03 +08:00
|
|
|
char msg[BLAH_MESSAGE];
|
2020-08-26 15:38:01 +08:00
|
|
|
va_list ap;
|
|
|
|
va_start(ap, format);
|
2020-08-28 10:44:03 +08:00
|
|
|
vsnprintf(msg, sizeof(char) * BLAH_MESSAGE, format, ap);
|
2020-08-26 15:38:01 +08:00
|
|
|
va_end(ap);
|
|
|
|
|
|
|
|
if (App::is_running() && App::config()->on_warn != nullptr)
|
|
|
|
{
|
|
|
|
App::config()->on_warn(msg);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
printf("\033[01;33mWARN:\033[0m\t%s\n", msg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Log::error(const char* format, ...)
|
|
|
|
{
|
2020-08-28 10:44:03 +08:00
|
|
|
char msg[BLAH_MESSAGE];
|
2020-08-26 15:38:01 +08:00
|
|
|
va_list ap;
|
|
|
|
va_start(ap, format);
|
2020-08-28 10:44:03 +08:00
|
|
|
vsnprintf(msg, sizeof(char) * BLAH_MESSAGE, format, ap);
|
2020-08-26 15:38:01 +08:00
|
|
|
va_end(ap);
|
|
|
|
|
|
|
|
if (App::is_running() && App::config()->on_error != nullptr)
|
|
|
|
{
|
|
|
|
App::config()->on_error(msg);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
printf("\033[1;31mERROR:\033[0m\t%s\n", msg);
|
|
|
|
}
|
|
|
|
}
|