#include "swapi.h"
#include "swlog.h"

// 声明Go中的日志函数(Go实现, 供C/C++调用)
extern void LogFromGo(const char *level, const char *file, int line, const char *message);

// 带有打印级别的打印输出(该函数会自动在行尾加入回车换行符)
void sw_log_writeWithLevel(ELogLevel level, const char *file, int line, const char *format, ...)
{
  char buf[8192] = { 0 };
  va_list ap;

  va_start(ap, format);
  vsnprintf(buf, sizeof(buf), format, ap);
  va_end(ap);

  switch(level)
  {
  case LEVEL_TRACE:
    LogFromGo("trace", file, line, buf);
    break;
  case LEVEL_DEBUG:
    LogFromGo("debug", file, line, buf);
    break;
  case LEVEL_INFO:
    LogFromGo("info",  file, line, buf);
    break;
  case LEVEL_WARN:
    LogFromGo("warn",  file, line, buf);
    break;
  case LEVEL_ERROR:
    LogFromGo("error", file, line, buf);
    break;
  case LEVEL_FATAL:
    LogFromGo("fatal", file, line, buf);
    break;
  }
}
