Aruna
aruna::log::channel_t Struct Reference

#include <log.h>

Public Member Functions

 channel_t (const char *name, level_t level=default_level)
 
 ~channel_t ()
 
int verbose (const char *format,...)
 log verbose message More...
 
int debug (const char *format,...)
 log debug message More...
 
int info (const char *format,...)
 log info message More...
 
int warning (const char *format,...)
 log warning message More...
 
int error (const char *format,...)
 log error message More...
 
int dump (level_t level, uint8_t *bin, size_t size)
 dump array of bin data More...
 
bool operator< (const channel_t &b) const
 
bool operator== (const char *name) const
 

Public Attributes

const char * name
 Channel name, used to identify. More...
 
level_t level = default_level
 max log level of channel More...
 
err_t startup_status = err_t::NOT_STARTED
 Contains the error happens at construction. More...
 

Private Member Functions

int print (level_t level, const char *format)
 
int out (const char *format,...)
 
unsigned long epoch ()
 

Detailed Description

Definition at line 25 of file log.h.

Constructor & Destructor Documentation

◆ channel_t()

aruna::log::channel_t::channel_t ( const char *  name,
level_t  level = default_level 
)

Definition at line 112 of file log.cpp.

112  : name(name), level(level) {
114  if (!register_channel(this))
116  }
const char * name
Channel name, used to identify.
Definition: log.h:29
err_t startup_status
Contains the error happens at construction.
Definition: log.h:43
int register_channel(channel_t *channel)
Definition: log.cpp:182
level_t level
max log level of channel
Definition: log.h:34
Here is the call graph for this function:

◆ ~channel_t()

aruna::log::channel_t::~channel_t ( )

Definition at line 178 of file log.cpp.

178  {
179  channels()->erase(this);
180  }
std::set< channel_t * > * channels()
Definition: log.cpp:24
Here is the call graph for this function:

Member Function Documentation

◆ debug()

int aruna::log::channel_t::debug ( const char *  format,
  ... 
)

log debug message

Parameters
format,chararray
...insert extra variables
Returns
how many bytes have been written.

Definition at line 51 of file log.cpp.

51  {
52  char buffer[256];
53  int n = 0;
54  va_list argptr;
55 
56  va_start(argptr, format);
57  vsprintf(buffer, format, argptr);
58  n = print(level_t::DEBUG, buffer);
59  va_end(argptr);
60 
61  return n;
62  }
int print(level_t level, const char *format)
Definition: log.cpp:103
Here is the call graph for this function:
Here is the caller graph for this function:

◆ dump()

int aruna::log::channel_t::dump ( level_t  level,
uint8_t *  bin,
size_t  size 
)

dump array of bin data

Parameters
levellog level
binpointer to array
sizesize of array
Returns
bytes written

Definition at line 135 of file log.cpp.

135  {
136 // TODO this if statement is copied two times, there should be a function that implements it
137  if (((int) level > (int) this->level) || ((int) level > (int) max_level) || level == level_t::NONE) {
138  return 0;
139  }
140 #if defined (__unix__) || (defined (__APPLE__) && defined (__MACH__))
141  char level_c[5];
142  level_t_to_char(level, level_c);
143 // TODO formatting should be staderlized
144  out("%s (%u) %s, 0x%X ", level_c, epoch(), name, bin);
145  for (int i = 0; i < size ; ++i) {
146  out("%02X ", bin[i]);
147  }
148  out("\n");
149  return size;
150 #elif defined(ESP_PLATFORM)
151  esp_log_level_t esp_log_level;
152  switch (level) {
153  case level_t::VERBOSE:
154  esp_log_level = ESP_LOG_VERBOSE;
155  break;
156  case level_t::DEBUG:
157  esp_log_level = ESP_LOG_DEBUG;
158  break;
159  case level_t::INFO:
160  esp_log_level = ESP_LOG_INFO;
161  break;
162  case level_t::WARNING:
163  esp_log_level = ESP_LOG_WARN;
164  break;
165  case level_t::ERROR:
166  esp_log_level = ESP_LOG_ERROR;
167  break;
168  default:
169  case log::level_t::NONE:
170  esp_log_level = ESP_LOG_NONE;
171  break;
172  }
173  ESP_LOG_BUFFER_HEXDUMP(name, bin, size, esp_log_level);
174  return size;
175 #endif
176  }
const char * name
Channel name, used to identify.
Definition: log.h:29
unsigned long epoch()
Definition: log.cpp:118
level_t max_level
Definition: log.cpp:29
level_t level
max log level of channel
Definition: log.h:34
void level_t_to_char(level_t level, char *buffer)
convert level_t object to char
Definition: log.cpp:215
int out(const char *format,...)
Definition: log.cpp:126
Here is the call graph for this function:
Here is the caller graph for this function:

◆ epoch()

unsigned long aruna::log::channel_t::epoch ( )
private

Definition at line 118 of file log.cpp.

118  {
119 #if defined (__unix__) || (defined (__APPLE__) && defined (__MACH__))
120  return ::time(NULL);
121 #elif defined(ESP_PLATFORM)
122  return esp_log_timestamp();
123 #endif
124  }
Here is the caller graph for this function:

◆ error()

int aruna::log::channel_t::error ( const char *  format,
  ... 
)

log error message

Parameters
format,chararray
...insert extra variables
Returns
how many bytes have been written.

Definition at line 90 of file log.cpp.

90  {
91  char buffer[256];
92  int n = 0;
93  va_list argptr;
94 
95  va_start(argptr, format);
96  vsprintf(buffer, format, argptr);
97  n = print(level_t::ERROR, buffer);
98  va_end(argptr);
99 
100  return n;
101  }
int print(level_t level, const char *format)
Definition: log.cpp:103
Here is the call graph for this function:
Here is the caller graph for this function:

◆ info()

int aruna::log::channel_t::info ( const char *  format,
  ... 
)

log info message

Parameters
format,chararray
...insert extra variables
Returns
how many bytes have been written.

Definition at line 64 of file log.cpp.

64  {
65  char buffer[256];
66  int n = 0;
67  va_list argptr;
68 
69  va_start(argptr, format);
70  vsprintf(buffer, format, argptr);
71  n = print(level_t::INFO, buffer);
72  va_end(argptr);
73 
74  return n;
75  }
int print(level_t level, const char *format)
Definition: log.cpp:103
Here is the call graph for this function:

◆ operator<()

bool aruna::log::channel_t::operator< ( const channel_t b) const
inline

Definition at line 89 of file log.h.

89  {
90  return this->name < b.name;
91  }
const char * name
Channel name, used to identify.
Definition: log.h:29

◆ operator==()

bool aruna::log::channel_t::operator== ( const char *  name) const
inline

Definition at line 93 of file log.h.

93  {
94  return this->name == name;
95  }
const char * name
Channel name, used to identify.
Definition: log.h:29
Here is the call graph for this function:

◆ out()

int aruna::log::channel_t::out ( const char *  format,
  ... 
)
private

Definition at line 126 of file log.cpp.

126  {
127  va_list list;
128  int n;
129  va_start(list, format);
130  n = print_function(format, list);
131  va_end(list);
132  return n;
133  }
vprintf_like_t print_function
Definition: log.cpp:30
Here is the caller graph for this function:

◆ print()

int aruna::log::channel_t::print ( level_t  level,
const char *  format 
)
private

Definition at line 103 of file log.cpp.

103  {
104  char level_txt[5];
105  if (((int) level > (int) this->level) || ((int) level > (int) max_level) || level == level_t::NONE) {
106  return 0;
107  }
108  level_t_to_char(level, level_txt);
109  return out("%s (%u) %s, %s\n", level_txt, epoch(), name, format);
110  }
const char * name
Channel name, used to identify.
Definition: log.h:29
unsigned long epoch()
Definition: log.cpp:118
level_t max_level
Definition: log.cpp:29
level_t level
max log level of channel
Definition: log.h:34
void level_t_to_char(level_t level, char *buffer)
convert level_t object to char
Definition: log.cpp:215
int out(const char *format,...)
Definition: log.cpp:126
Here is the call graph for this function:
Here is the caller graph for this function:

◆ verbose()

int aruna::log::channel_t::verbose ( const char *  format,
  ... 
)

log verbose message

Parameters
format,chararray
...insert extra variables
Returns
how many bytes have been written.

Definition at line 38 of file log.cpp.

38  {
39  char buffer[256];
40  int n = 0;
41  va_list argptr;
42 
43  va_start(argptr, format);
44  vsprintf(buffer, format, argptr);
45  n = print(level_t::VERBOSE, buffer);
46  va_end(argptr);
47 
48  return n;
49  }
int print(level_t level, const char *format)
Definition: log.cpp:103
Here is the call graph for this function:
Here is the caller graph for this function:

◆ warning()

int aruna::log::channel_t::warning ( const char *  format,
  ... 
)

log warning message

Parameters
format,chararray
...insert extra variables
Returns
how many bytes have been written.

Definition at line 77 of file log.cpp.

77  {
78  char buffer[256];
79  int n = 0;
80  va_list argptr;
81 
82  va_start(argptr, format);
83  vsprintf(buffer, format, argptr);
84  n = print(level_t::WARNING, buffer);
85  va_end(argptr);
86 
87  return n;
88  }
int print(level_t level, const char *format)
Definition: log.cpp:103
Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ level

level_t aruna::log::channel_t::level = default_level

max log level of channel

Definition at line 34 of file log.h.

◆ name

const char* aruna::log::channel_t::name

Channel name, used to identify.

Definition at line 29 of file log.h.

◆ startup_status

err_t aruna::log::channel_t::startup_status = err_t::NOT_STARTED

Contains the error happens at construction.

Definition at line 43 of file log.h.


The documentation for this struct was generated from the following files: