Aruna
log.h
Go to the documentation of this file.
1 //
2 // Created by noeel on 17-7-19.
3 //
4 
5 #ifndef ARUNA_LOG_H
6 #define ARUNA_LOG_H
7 
8 #include "stdarg.h"
9 #include "stddef.h"
10 #include "stdint.h"
11 #include "arunaTypes.h"
12 namespace aruna { namespace log {
13  enum class level_t: int {
14  NONE = -1,
15  VERBOSE = 4,
16  DEBUG = 3,
17  INFO = 2,
18  WARNING = 1,
19  ERROR = 0,
20  };
21  typedef int (*vprintf_like_t)(const char *, va_list);
23 
24 
25  struct channel_t {
29  const char* name;
30 
35 
36  channel_t(const char* name, level_t level = default_level);
37 
38  ~channel_t();
39 
43  err_t startup_status = err_t::NOT_STARTED;
44 
51  int verbose(const char* format, ...);
58  int debug(const char* format, ...);
65  int info(const char* format, ...);
72  int warning(const char* format, ...);
79  int error(const char* format, ...);
87  int dump(level_t level, uint8_t *bin, size_t size);
88 
89  bool operator<(const channel_t &b) const {
90  return this->name < b.name;
91  }
92 
93  bool operator==(const char* name) const {
94  return this->name == name;
95  }
96 
97  private:
98  int print(level_t level, const char *format);
99  int out(const char *format, ...);
100  unsigned long epoch();
101 
102  };
103 
110  int set_level(const char *channel_name, level_t new_level);
111 
118 
125 
131  void level_t_to_char(level_t level, char *buffer);
132 
133 }}
134 
135 #endif //ARUNA_LOG_H
Definition: comm.cpp:14
vprintf_like_t set_print_function(vprintf_like_t func)
Set a new print function to log to a diffrent location.
Definition: log.cpp:203
const char * name
Channel name, used to identify.
Definition: log.h:29
static log::channel_t * log
Definition: comm.cpp:23
level_t set_max_level(level_t level)
set maximum print level for all channels
Definition: log.cpp:209
int(* vprintf_like_t)(const char *, va_list)
Definition: log.h:21
bool operator<(const channel_t &b) const
Definition: log.h:89
sis::level_t level[(uint8_t) sis::type_t::MAX]
Definition: watcher.cpp:16
static const level_t default_level
Definition: log.h:22
int set_level(const char *channel_name, level_t new_level)
Set level of log channel.
Definition: log.cpp:191
void level_t_to_char(level_t level, char *buffer)
convert level_t object to char
Definition: log.cpp:215
bool operator==(const char *name) const
Definition: log.h:93
level_t
Definition: log.h:13