2021-05-10 08:23:02 +08:00
|
|
|
#include <blah/common.h>
|
|
|
|
#include <blah/app.h>
|
2020-08-26 15:38:01 +08:00
|
|
|
#include <stdarg.h> // for logging methods
|
|
|
|
#include <stdio.h> // for sprintf
|
|
|
|
|
|
|
|
using namespace Blah;
|
|
|
|
|
2021-03-21 08:33:04 +08:00
|
|
|
void Log::info(const char* format, ...)
|
2020-08-26 15:38:01 +08:00
|
|
|
{
|
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);
|
|
|
|
|
2021-05-10 10:40:50 +08:00
|
|
|
if (App::config().on_log)
|
2020-08-26 15:38:01 +08:00
|
|
|
{
|
2021-05-10 10:40:50 +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, ...)
|
|
|
|
{
|
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);
|
|
|
|
|
2021-05-10 10:40:50 +08:00
|
|
|
if (App::config().on_log)
|
2020-08-26 15:38:01 +08:00
|
|
|
{
|
2021-05-10 10:40:50 +08:00
|
|
|
App::config().on_log(msg, Category::Warning);
|
2020-08-26 15:38:01 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-02-22 10:43:42 +08:00
|
|
|
printf("WARN: %s\n", msg);
|
2020-08-26 15:38:01 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
2021-05-10 10:40:50 +08:00
|
|
|
if (App::config().on_log)
|
2020-08-26 15:38:01 +08:00
|
|
|
{
|
2021-05-10 10:40:50 +08:00
|
|
|
App::config().on_log(msg, Category::Error);
|
2020-08-26 15:38:01 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-02-22 10:43:42 +08:00
|
|
|
printf("ERROR: %s\n", msg);
|
2020-08-26 15:38:01 +08:00
|
|
|
}
|
|
|
|
}
|