#include <stdio.h>
#include <stdarg.h>

#include "logging.h"

int argent_log_level;

const char *level_string(int level)
{
   switch(level) {
   case FATAL:
      return "FATAL";
   case ERROR:
      return "ERROR";
   case WARN:
      return "WARN";
   case INFO:
      return "INFO";
   case DEBUG:
      return "DEBUG";
   case TRACE:
      return "TRACE";

   default:
      if (level > TRACE)
	 return "TRACE";
      return "[BAD LOG LEVEL]";
   }
}


void argent_log(int level, const char *format_string, ...)
{
   if (argent_log_level >= level) {
      va_list args;
      va_start(args, format_string);
      fprintf(stderr, "[%s] ", level_string(level));
      vfprintf(stderr, format_string, args);
      fprintf(stderr, "\n");
      va_end(args);
   }
}