RF24Log  0.1.3
Unified logging library
AllLogLevels.ino

This example just prints a messaged for each supported log level. 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/AllLogLevelsLogger%\n");
39 }
40 
41 void loop()
42 {
43  uint8_t lvl = 0;
44  do {
45  RF24Log_log(lvl, vendorID, "A log message from %s on level %3d", "loop()", lvl);
46  lvl++;
47  } while (lvl);
48 
49  // NOTE: level 0 skips outputting the timestamp and level description
50  RF24Log_log(0, DisableVendor, "\nEnter a log level (in octal form) to demonstrate filtering messages\n");
51 
52  delay(5000);
53 
54  uint8_t level = 0;
55  if (Serial.available()) {
56  char input = Serial.read();
57  while (Serial.available() && input >= 48 && input < 56) {
58  level <<= 3;
59  level += input - 48;
60  input = Serial.read();
61  }
62  RF24Log_log(0, DisableVendor, "Setting log level (in octal) to %o", level);
63  serialLogHandler.setLogLevel(level);
64  }
65 }
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_info(vendorId, message,...)
output an INFO message
Definition: RF24Logging.h:68
RF24Logging rf24Logging
default logger instance
Definition: RF24Logging.cpp:61
@ ALL
Definition: RF24LogLevel.h:51