MCU-Common
Modules useful for embedded (MCU) programming
logger.h File Reference
#include <stdbool.h>
#include <stdio.h>
#include <mcu-common/macros.h>
#include <mcu-common/fifo.h>
Include dependency graph for logger.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  logger_entry
 Logger entry (used internally) More...
 
struct  logger
 Logger instance. More...
 

Macros

#define LOGGER_PUT_IMPL_N(n)   LOGGER_PUT_ARGC##n
 
#define LOGGER_PUT_IMPL(log, argc, ...)    LOGGER_PUT_IMPL_N(argc)(log, __VA_ARGS__)
 
#define LOGGER_PUT_ARGC1(log, fmt)    logger_put0((log), (fmt))
 
#define LOGGER_PUT_ARGC2(log, fmt, a0)    logger_put1((log), (fmt), (int)(a0))
 
#define LOGGER_PUT_ARGC3(log, fmt, a0, a1)    logger_put2((log), (fmt), (int)(a0), (int)(a1))
 
#define LOGGER_PUT_ARGC4(log, fmt, a0, a1, a2)    logger_put3((log), (fmt), (int)(a0), (int)(a1), (int)(a2))
 
#define LOGGER_PUT_ARGC5(log, fmt, a0, a1, a2, a3)    logger_put4((log), (fmt), (int)(a0), (int)(a1), (int)(a2), (int)(a3))
 
#define LOGGER_PUT_ARGC6(log, fmt, a0, a1, a2, a3, a4)    logger_put5((log), (fmt), (int)(a0), (int)(a1), (int)(a2), (int)(a3), (int)(a4))
 
#define LOGGER_PUT_ARGC7(log, fmt, a0, a1, a2, a3, a4, a5)    logger_put6((log), (fmt), (int)(a0), (int)(a1), (int)(a2), (int)(a3), (int)(a4), (int)(a5))
 
#define LOGGER_MAX_ARGC   6
 The maximum number of logger_put() arguments supported by the implementation. More...
 
#define LOGGER_INIT(log, log_write_cb, log_capacity, str_capacity)
 Initializes the logger instance and allocates its string and FIFO buffers. More...
 
#define LOGGER_PUT(log, ...)    logger_put(log, VA_ARGC(__VA_ARGS__), __VA_ARGS__)
 Logs a message. More...
 

Functions

bool logger_init (struct logger *log)
 Initializes logger. More...
 
bool logger_put (const struct logger *log, int argc, const char *fmt,...)
 Logs a message (puts it into internal buffer for later processing). More...
 
bool logger_process (const struct logger *log)
 Processes a single logged message from the buffer. More...
 
bool logger_put0 (const struct logger *log, const char *fmt)
 Inserts a message to the logger. More...
 
bool logger_put1 (const struct logger *log, const char *fmt, int arg0)
 Inserts a message to the logger. More...
 
bool logger_put2 (const struct logger *log, const char *fmt, int arg0, int arg1)
 Inserts a message to the logger. More...
 
bool logger_put3 (const struct logger *log, const char *fmt, int arg0, int arg1, int arg2)
 Inserts a message to the logger. More...
 
bool logger_put4 (const struct logger *log, const char *fmt, int arg0, int arg1, int arg2, int arg3)
 Inserts a message to the logger. More...
 
bool logger_put5 (const struct logger *log, const char *fmt, int arg0, int arg1, int arg2, int arg3, int arg4)
 Inserts a message to the logger. More...
 
bool logger_put6 (const struct logger *log, const char *fmt, int arg0, int arg1, int arg2, int arg3, int arg4, int arg5)
 Inserts a message to the logger. More...
 

Macro Definition Documentation

◆ LOGGER_PUT_IMPL_N

#define LOGGER_PUT_IMPL_N (   n)    LOGGER_PUT_ARGC##n

◆ LOGGER_PUT_IMPL

#define LOGGER_PUT_IMPL (   log,
  argc,
  ... 
)     LOGGER_PUT_IMPL_N(argc)(log, __VA_ARGS__)

◆ LOGGER_PUT_ARGC1

#define LOGGER_PUT_ARGC1 (   log,
  fmt 
)     logger_put0((log), (fmt))

◆ LOGGER_PUT_ARGC2

#define LOGGER_PUT_ARGC2 (   log,
  fmt,
  a0 
)     logger_put1((log), (fmt), (int)(a0))

◆ LOGGER_PUT_ARGC3

#define LOGGER_PUT_ARGC3 (   log,
  fmt,
  a0,
  a1 
)     logger_put2((log), (fmt), (int)(a0), (int)(a1))

◆ LOGGER_PUT_ARGC4

#define LOGGER_PUT_ARGC4 (   log,
  fmt,
  a0,
  a1,
  a2 
)     logger_put3((log), (fmt), (int)(a0), (int)(a1), (int)(a2))

◆ LOGGER_PUT_ARGC5

#define LOGGER_PUT_ARGC5 (   log,
  fmt,
  a0,
  a1,
  a2,
  a3 
)     logger_put4((log), (fmt), (int)(a0), (int)(a1), (int)(a2), (int)(a3))

◆ LOGGER_PUT_ARGC6

#define LOGGER_PUT_ARGC6 (   log,
  fmt,
  a0,
  a1,
  a2,
  a3,
  a4 
)     logger_put5((log), (fmt), (int)(a0), (int)(a1), (int)(a2), (int)(a3), (int)(a4))

◆ LOGGER_PUT_ARGC7

#define LOGGER_PUT_ARGC7 (   log,
  fmt,
  a0,
  a1,
  a2,
  a3,
  a4,
  a5 
)     logger_put6((log), (fmt), (int)(a0), (int)(a1), (int)(a2), (int)(a3), (int)(a4), (int)(a5))

Function Documentation

◆ logger_put0()

bool logger_put0 ( const struct logger log,
const char *  fmt 
)

Inserts a message to the logger.

Parameters
logPointer to the logger structure
fmtPointer to a formatted string (for sprintf)
Returns
true if message was put inserted successfully, false otherwise

◆ logger_put1()

bool logger_put1 ( const struct logger log,
const char *  fmt,
int  arg0 
)

Inserts a message to the logger.

Parameters
logPointer to the logger structure
fmtPointer to a formatted string to be passed to sprintf
arg0Argument to be passed to sprintf
Returns
true if message was put inserted successfully, false otherwise

◆ logger_put2()

bool logger_put2 ( const struct logger log,
const char *  fmt,
int  arg0,
int  arg1 
)

Inserts a message to the logger.

Parameters
logPointer to the logger structure
fmtPointer to a formatted string to be passed to sprintf
arg0,arg1Arguments to be passed to sprintf
Returns
true if message was put inserted successfully, false otherwise

◆ logger_put3()

bool logger_put3 ( const struct logger log,
const char *  fmt,
int  arg0,
int  arg1,
int  arg2 
)

Inserts a message to the logger.

Parameters
logPointer to the logger structure
fmtPointer to a formatted string to be passed to sprintf
arg0,arg1,arg2Arguments to be passed to sprintf
Returns
true if message was put inserted successfully, false otherwise

◆ logger_put4()

bool logger_put4 ( const struct logger log,
const char *  fmt,
int  arg0,
int  arg1,
int  arg2,
int  arg3 
)

Inserts a message to the logger.

Parameters
logPointer to the logger structure
fmtPointer to a formatted string to be passed to sprintf
arg0,arg1,arg2,arg3Arguments to be passed to sprintf
Returns
true if message was put inserted successfully, false otherwise

◆ logger_put5()

bool logger_put5 ( const struct logger log,
const char *  fmt,
int  arg0,
int  arg1,
int  arg2,
int  arg3,
int  arg4 
)

Inserts a message to the logger.

Parameters
logPointer to the logger structure
fmtPointer to a formatted string to be passed to sprintf
arg0,arg1,arg2,arg3,arg4Arguments to be passed to sprintf
Returns
true if message was put inserted successfully, false otherwise

◆ logger_put6()

bool logger_put6 ( const struct logger log,
const char *  fmt,
int  arg0,
int  arg1,
int  arg2,
int  arg3,
int  arg4,
int  arg5 
)

Inserts a message to the logger.

Parameters
logPointer to the logger structure
fmtPointer to a formatted string to be passed to sprintf
arg0,arg1,arg2,arg3,arg4,arg5Arguments to be passed to sprintf
Returns
true if message was put inserted successfully, false otherwise