RF24Log  0.1.3
Unified logging library
DualStream.ino

This example uses a handler extension to forward log messages to 2 simultaneous out put streams. 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>
20 
21 // Create first hardware serial port log handler
22 ArduinoPrintLogger serialLogHandler1(&Serial);
23 
24 // Create second hardware serial port log handler
25 ArduinoPrintLogger serialLogHandler2(&Serial);
26 
27 RF24LogDualHandler dualHandler(&serialLogHandler1, &serialLogHandler2);
28 
29 // Define global vendor id (it is stored in FLASH memory)
30 const char PROGMEM vendorID[] = "RF24LogExample";
31 const char PROGMEM DisableVendor[] = ""; // vendorId needs to be a flash string on AVR architecture
32 
33 // we will use this variable to control the filtering of log messages for the second handler
34 uint8_t level = RF24LogLevel::ALL;
35 
36 void setup()
37 {
38  // configure serial port baudrate
39  Serial.begin(115200);
40  while (!Serial) {/* some boards need this */}
41 
42  // set maximal log level to ALL (for both handlers)
43  dualHandler.setLogLevel(RF24LogLevel::ALL);
44  // set serial port handler (to only 1 handler)
45  rf24Logging.setHandler(&serialLogHandler1);
46 
47  RF24Log_info(vendorID, "RF24Log/examples/DualLogger%\n");
48 }
49 
50 void loop()
51 {
52  // set serial port handler (to both handlers)
53  rf24Logging.setHandler(&dualHandler);
54  bool is_2nd_handler_enabled_for_info;
55  is_2nd_handler_enabled_for_info = level < RF24LogLevel::INFO;
56  RF24Log_info(vendorID,
57  "This info message should be logged %s because serialLogHandler2 verbosity is %o.",
58  (is_2nd_handler_enabled_for_info ? "once" : "twice"),
59  level);
60 
61  // set serial port handler (to only 1 handler)
62  rf24Logging.setHandler(&serialLogHandler1);
63  RF24Log_debug(vendorID, "This debug message should be logged once.");
64 
65  // NOTE: level 0 skips outputting the timestamp and level description
66  RF24Log_log(0, DisableVendor, "\nEnter a log level (in octal form) to demonstrate filtering messages (for the second handler)\n");
67 
68  delay(5000);
69 
70  if (Serial.available()) {
71  level = 0; // reset value for the following arithmatic
72  char input = Serial.read();
73  while (Serial.available() && input >= 48 && input < 56) {
74  level <<= 3;
75  level += input - 48;
76  input = Serial.read();
77  }
78  RF24Log_log(0, DisableVendor, "Setting log level (in octal) to %o (for the second handler)", level);
79  serialLogHandler2.setLogLevel(level);
80  }
81 }
handler for Print::print() function calls based on Arduino API
handler extention to manage 2 handlers
Provides rf24Logging singleton for accessing the Logging API.
A log handler implementation which outputs log messages to a stream.
Module to extend the RF24LogBaseHandler mechanism for redirecting to 2 different RF24LogBaseHandler o...
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
RF24Logging rf24Logging
default logger instance
Definition: RF24Logging.cpp:61
@ INFO
Definition: RF24LogLevel.h:47
@ ALL
Definition: RF24LogLevel.h:51