RF24Log  0.1.3
Unified logging library
gettingStarted.ino

A Basic usage of RF24Logging on the Arduino IDE's Serial Monitor. This example accepts user input to change the log level used as a filter.

1 
15 #include <string.h>
16 #include <Arduino.h>
17 #include <RF24Logging.h>
19 
20 // Create hardware serial port log handler
21 ArduinoPrintLogger serialLogHandler(&Serial);
22 
23 // Define global vendor id (it is stored in FLASH memory)
24 const char PROGMEM vendorID[] = "RF24LogExample";
25 const char PROGMEM DisableVendor[] = ""; // vendorId needs to be a flash string on AVR architecture
26 
27 void setup()
28 {
29  // configure serial port baudrate
30  Serial.begin(115200);
31  while (!Serial) {/* some boards need this */}
32 
33  // set maximal log level to ALL
34  serialLogHandler.setLogLevel(RF24LogLevel::ALL);
35  // set serial port handler
36  rf24Logging.setHandler(&serialLogHandler);
37 
38  RF24Log_info(vendorID, "RF24Log/examples/gettingStarted%\n");
39 }
40 
41 void loop()
42 {
43  RF24Log_warn(vendorID, "Warn with error code = 0x%x%x%x%x", 222, 173, 190, 239);
44  RF24Log_error(vendorID, "Error message with %s", "RAM string");
45  RF24Log_info(vendorID, "Info about rounding a double value %.4D", 3.14159);
46  RF24Log_debug(vendorID, "Debug precision of a double value %.4D", 2.71);
47 
48  RF24Log_log(RF24LogLevel::INFO + 1, vendorID, "message on sublevel INFO + 1");
49  RF24Log_log(RF24LogLevel::WARN + 1, vendorID, "message on sublevel WARN + 1");
50  RF24Log_log(RF24LogLevel::INFO + 7, vendorID, "message on sublevel INFO + 7");
51  RF24Log_log(RF24LogLevel::ERROR - 1, vendorID, "message on sublevel ERROR - 1");
52  RF24Log_log(RF24LogLevel::DEBUG + 8, vendorID, "message on sublevel DEBUG + 8");
53 
54  RF24Log_log(077, vendorID, "This\n\tis a multiline\n\t\tmessage that\n\tends with a\nblank line\n\n");
55  RF24Log_log(75, vendorID, "%%%%This is level 0x%02x (0b%08b or%4d)%2c", 75, 75, 75, '!');
56 
57  // NOTE: negative numbers will look strange in binary, hexadecimal, and octal output if they aren't first casted as unsigned numbers
58  RF24Log_log((uint8_t)(-0xAA), vendorID, "0x%02x is 0b%08b is %d, but can also be %hho", (uint8_t)(-0xAA), (uint8_t)(-0xAA), -0xAA, -0xAA);
59 
60  // NOTE: level 0 skips outputting the timestamp and level description
61  RF24Log_log(0, DisableVendor, "\nEnter a log level (in octal form) to demonstrate filtering messages\n");
62 
63  delay(5000);
64 
65  uint8_t level = 0;
66  if (Serial.available()) {
67  char input = Serial.read();
68  while (Serial.available() && input >= 48 && input < 56) {
69  level <<= 3;
70  level += input - 48;
71  input = Serial.read();
72  }
73  RF24Log_log(0, DisableVendor, "Setting log level (in octal) to %o", level);
74  serialLogHandler.setLogLevel(level);
75  }
76 }
handler for Print::print() function calls based on Arduino API
Provides rf24Logging singleton for accessing the Logging API.
A log handler implementation which outputs log messages to a stream.
void setHandler(RF24LogBaseHandler *handler)
set the instance's handler
Definition: RF24Logging.cpp:25
#define RF24Log_log(logLevel, vendorId, message,...)
output a log message of any level
Definition: RF24Logging.h:88
#define RF24Log_debug(vendorId, message,...)
output a message to help developers DEBUG their source code
Definition: RF24Logging.h:77
#define RF24Log_info(vendorId, message,...)
output an INFO message
Definition: RF24Logging.h:68
#define RF24Log_error(vendorId, message,...)
ouput an ERROR message
Definition: RF24Logging.h:50
RF24Logging rf24Logging
default logger instance
Definition: RF24Logging.cpp:61
#define RF24Log_warn(vendorId, message,...)
output a message to WARN the reader
Definition: RF24Logging.h:59
@ DEBUG
Definition: RF24LogLevel.h:49
@ ERROR
Definition: RF24LogLevel.h:43
@ INFO
Definition: RF24LogLevel.h:47
@ WARN
Definition: RF24LogLevel.h:45
@ ALL
Definition: RF24LogLevel.h:51