Aruna
aruna::log Namespace Reference

Classes

struct  channel_t
 

Typedefs

typedef int(* vprintf_like_t) (const char *, va_list)
 

Enumerations

enum  level_t : int {
  level_t::NONE = -1, level_t::VERBOSE = 4, level_t::DEBUG = 3, level_t::INFO = 2,
  level_t::WARNING = 1, level_t::ERROR = 0
}
 

Functions

std::set< channel_t * > * channels ()
 
int register_channel (channel_t *channel)
 
int set_level (const char *channel_name, level_t new_level)
 Set level of log channel. More...
 
vprintf_like_t set_print_function (vprintf_like_t func)
 Set a new print function to log to a diffrent location. More...
 
level_t set_max_level (level_t level)
 set maximum print level for all channels More...
 
void level_t_to_char (level_t level, char *buffer)
 convert level_t object to char More...
 

Variables

level_t max_level = level_t::VERBOSE
 
vprintf_like_t print_function = vprintf
 
static const level_t default_level = level_t::INFO
 

Typedef Documentation

◆ vprintf_like_t

typedef int(* aruna::log::vprintf_like_t) (const char *, va_list)

Definition at line 21 of file log.h.

Enumeration Type Documentation

◆ level_t

enum aruna::log::level_t : int
strong
Enumerator
NONE 
VERBOSE 
DEBUG 
INFO 
WARNING 
ERROR 

Definition at line 13 of file log.h.

Function Documentation

◆ channels()

std::set<channel_t*>* aruna::log::channels ( )

Definition at line 24 of file log.cpp.

24  {
25 // mitigate Static Initialization Order Fiasco
26  static std::set<channel_t*> channels;
27  return &channels;
28  }
std::set< channel_t * > * channels()
Definition: log.cpp:24
Here is the caller graph for this function:

◆ level_t_to_char()

void aruna::log::level_t_to_char ( level_t  level,
char *  buffer 
)

convert level_t object to char

Parameters
levellevel_t
bufferminimal size of 5.

Definition at line 215 of file log.cpp.

215  {
216  switch (level) {
217  case log::level_t::NONE:
218  strcpy(buffer, "NONE ");
219  break;
220  case level_t::VERBOSE:
221  strcpy(buffer, "VERBO");
222  break;
223  case level_t::DEBUG:
224  strcpy(buffer, "DEBUG");
225  break;
226  case level_t::INFO:
227  strcpy(buffer, "INFO ");
228  break;
229  case level_t::WARNING:
230  strcpy(buffer, "WARN ");
231  break;
232  case level_t::ERROR:
233  strcpy(buffer, "ERROR");
234  break;
235  default:
236  strcpy(buffer, "lvler");
237  break;
238  }
239  }
sis::level_t level[(uint8_t) sis::type_t::MAX]
Definition: watcher.cpp:16
Here is the caller graph for this function:

◆ register_channel()

int aruna::log::register_channel ( channel_t channel)

Definition at line 182 of file log.cpp.

182  {
183  for (auto candidate: *channels()) {
184  if (!strcmp(candidate->name, channel->name)) {
185  return 0;
186  }
187  }
188  return channels()->insert(channel).second;
189  }
std::set< channel_t * > * channels()
Definition: log.cpp:24
Here is the call graph for this function:
Here is the caller graph for this function:

◆ set_level()

int aruna::log::set_level ( const char *  channel_name,
level_t  new_level 
)

Set level of log channel.

Parameters
channel_name,nameof the channel
new_levellevel_t max log level for the channel
Returns
0 if channel is unavailable, 1 if succeded

Definition at line 191 of file log.cpp.

191  {
192 // TODO set level on channel instead of log manager
193  int success = false;
194  for (auto candidate: *channels()) {
195  if (!strcmp(candidate->name, channel_name)) {
196  success = true;
197  candidate->level = new_level;
198  }
199  }
200  return success;
201  }
std::set< channel_t * > * channels()
Definition: log.cpp:24
Here is the call graph for this function:
Here is the caller graph for this function:

◆ set_max_level()

level_t aruna::log::set_max_level ( level_t  level)

set maximum print level for all channels

Parameters
levelnew max print level
Returns
old max print level

Definition at line 209 of file log.cpp.

209  {
210  level_t old_max_level = max_level;
211  max_level = level;
212  return old_max_level;
213  }
level_t max_level
Definition: log.cpp:29
sis::level_t level[(uint8_t) sis::type_t::MAX]
Definition: watcher.cpp:16
level_t
Definition: log.h:13
Here is the caller graph for this function:

◆ set_print_function()

vprintf_like_t aruna::log::set_print_function ( vprintf_like_t  func)

Set a new print function to log to a diffrent location.

Parameters
funcnew print function
Returns
old print function

Definition at line 203 of file log.cpp.

203  {
204  vprintf_like_t old_func = print_function;
205  print_function = func;
206  return old_func;
207  }
int(* vprintf_like_t)(const char *, va_list)
Definition: log.h:21
vprintf_like_t print_function
Definition: log.cpp:30
Here is the caller graph for this function:

Variable Documentation

◆ default_level

const level_t aruna::log::default_level = level_t::INFO
static

Definition at line 22 of file log.h.

◆ max_level

level_t aruna::log::max_level = level_t::VERBOSE

Definition at line 29 of file log.cpp.

◆ print_function

vprintf_like_t aruna::log::print_function = vprintf

Definition at line 30 of file log.cpp.