Bluenet  5.7.0
Bluenet, firmware for nRF52 smart home devices
Loading...
Searching...
No Matches
cs_Logger.h File Reference
#include <cfg/cs_Strings.h>
#include <protocol/cs_SerialTypes.h>
#include <protocol/cs_UartMsgTypes.h>
#include <cstdint>
#include <logging/impl/cs_LogPlainText.h>
Include dependency graph for cs_Logger.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define LOGnone(fmt, ...)
 Logger class. More...
 
#define LOG_FLUSH()
 
#define LOGvv(fmt, ...)   _log(SERIAL_VERY_VERBOSE, true, fmt, ##__VA_ARGS__)
 
#define LOGv(fmt, ...)   _log(SERIAL_VERBOSE, true, fmt, ##__VA_ARGS__)
 
#define LOGd(fmt, ...)   _log(SERIAL_DEBUG, true, fmt, ##__VA_ARGS__)
 
#define LOGi(fmt, ...)   _log(SERIAL_INFO, true, fmt, ##__VA_ARGS__)
 
#define LOGw(fmt, ...)   _log(SERIAL_WARN, true, fmt, ##__VA_ARGS__)
 
#define LOGe(fmt, ...)   _log(SERIAL_ERROR, true, fmt, ##__VA_ARGS__)
 
#define LOGf(fmt, ...)   _log(SERIAL_FATAL, true, fmt, ##__VA_ARGS__)
 

Macro Definition Documentation

◆ LOG_FLUSH

#define LOG_FLUSH ( )

◆ LOGd

#define LOGd (   fmt,
  ... 
)    _log(SERIAL_DEBUG, true, fmt, ##__VA_ARGS__)

◆ LOGe

#define LOGe (   fmt,
  ... 
)    _log(SERIAL_ERROR, true, fmt, ##__VA_ARGS__)

◆ LOGf

#define LOGf (   fmt,
  ... 
)    _log(SERIAL_FATAL, true, fmt, ##__VA_ARGS__)

◆ LOGi

#define LOGi (   fmt,
  ... 
)    _log(SERIAL_INFO, true, fmt, ##__VA_ARGS__)

◆ LOGnone

#define LOGnone (   fmt,
  ... 
)

Logger class.

Generally, you want to use: LOGnone, LOGv, LOGd, LOGi, LOGw, LOGe, or LOGf. These can be used like printf(), except that they will always add a newline.

To log an array of data, use one of: _logArray(level, addNewLine, pointer, size); _logArray(level, addNewLine, pointer, size, elementFmt); _logArray(level, addNewLine, pointer, size, startFmt, endFmt); _logArray(level, addNewLine, pointer, size, startFmt, endFmt, elementFmt); _logArray(level, addNewLine, pointer, size, startFmt, endFmt, elementFmt, seperationFmt); _logArray(level, addNewLine, pointer, size, startFmt, endFmt, elementFmt, seperationFmt, reverse); With:

  • level: uint8_t The log level, for example SERIAL_INFO.
  • addNewLine bool Whether to add a new line after this log.
  • pointer T* Pointer to the array.
  • size size_t Size of the array.
  • startFmt char* Optional string to start the log. Default: "[".
  • endFmt char* Optional string to end the log. Default: "]".
  • elementFmt char* Optional string to format an element value. Default depends on the element type. Example: "%u" for an unsigned integer.
  • seperationFmt char* Optional string to separate element values. Default: ", ".
  • reverse bool Whether to print the array from last to first element.

The log functions have to be macros, so they can add the filename and line number to the logs.

With binary logging, the arguments are not first converted into plain text before sending them over the UART. This is why templated and specialized functions are required for the implementation. This saves a lot of bytes to be sent, and saves binary size, as the strings do not end up in the firmware.

Since the log functions have an unknown amount of arguments, these macros require a variadic macro as well. See http://www.wikiwand.com/en/Variadic_macro. The two ## are e.g. a gcc specific extension that removes the , so that the ... arguments can also be left out.

◆ LOGv

#define LOGv (   fmt,
  ... 
)    _log(SERIAL_VERBOSE, true, fmt, ##__VA_ARGS__)

◆ LOGvv

#define LOGvv (   fmt,
  ... 
)    _log(SERIAL_VERY_VERBOSE, true, fmt, ##__VA_ARGS__)

◆ LOGw

#define LOGw (   fmt,
  ... 
)    _log(SERIAL_WARN, true, fmt, ##__VA_ARGS__)