summaryrefslogtreecommitdiff
path: root/src/logging/logging.c
blob: 82895d4a29a3a916ca089420e0f09f4982d6aed4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#include <stdio.h>
#include <stdarg.h>

#include "logging/logging.h"


struct honey_log_info_t honey_log_info;


const char * honey_log_level_str()
{
   switch(honey_log_info.log_level) {
   case DEBUG:
      return "DEBUG";
      break;

   case INFO:
      return "INFO";
      break;

   case WARN:
      return "WARN";
      break;

   case ERROR:
      return "ERROR";
      break;

   case FATAL:
      return "FATAL";
      break;

   default:
      return NULL;
      break;
   }
}


void honey_log_set_level(enum honey_log_level_t level)
{
   honey_log_info.log_level = level;
}


enum honey_log_level_t honey_log_get_level()
{
   return honey_log_info.log_level;
}


void honey_log_set_file(FILE* file)
{
   honey_log_info.log_file = file;
}


FILE * honey_log_get_file()
{
   return honey_log_info.log_file;
}


void honey_log(enum honey_log_level_t required_level,
	       const char *prefix,
	       const char *fmt, ...)
{
   if (honey_log_info.log_file == NULL)
      return;
   
   if (honey_log_info.log_level >= required_level) {
      va_list args;
      va_start(args, fmt);
      fprintf(honey_log_info.log_file, prefix);
      vfprintf(honey_log_info.log_file, fmt, args);
      va_end(args);
   }
}