blah/src/common.cpp

60 lines
1.0 KiB
C++
Raw Normal View History

#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;
void Log::info(const char* format, ...)
2020-08-26 15:38:01 +08:00
{
char msg[BLAH_MESSAGE];
2020-08-26 15:38:01 +08:00
va_list ap;
va_start(ap, format);
vsnprintf(msg, sizeof(char) * BLAH_MESSAGE, format, ap);
2020-08-26 15:38:01 +08:00
va_end(ap);
if (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[BLAH_MESSAGE];
2020-08-26 15:38:01 +08:00
va_list ap;
va_start(ap, format);
vsnprintf(msg, sizeof(char) * BLAH_MESSAGE, format, ap);
2020-08-26 15:38:01 +08:00
va_end(ap);
if (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[BLAH_MESSAGE];
2020-08-26 15:38:01 +08:00
va_list ap;
va_start(ap, format);
vsnprintf(msg, sizeof(char) * BLAH_MESSAGE, format, ap);
2020-08-26 15:38:01 +08:00
va_end(ap);
if (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
}
}