### Setup Logging Outputs Source: https://github.com/mathieucarbou/mycilalogger/blob/main/docs/index.md Configure the output streams for logging in the setup() method. Supports standard Serial and WebSerial. ```c++ Serial.begin(115200); logger.forwardTo(&Serial); ``` ```c++ WebSerial.begin(...); logger.forwardTo(&Serial); ``` -------------------------------- ### Setup Logging Outputs Source: https://github.com/mathieucarbou/mycilalogger/blob/main/README.md Configure the output streams for logs in the setup() method. Supports multiple outputs like Serial and WebSerial. ```c++ Serial.begin(115200); logger.forwardTo(&Serial); WebSerial.begin(...); logger.forwardTo(&Serial); ``` -------------------------------- ### Example Log Output Source: https://github.com/mathieucarbou/mycilalogger/blob/main/docs/index.md Illustrates the format of a typical log message, including task name, core ID, and tag. ```text D 8102600 loopTask (1) WEBSITE Published in 38 ms ``` -------------------------------- ### `forwardTo` — Register a log output Source: https://context7.com/mathieucarbou/mycilalogger/llms.txt Registers any `Print`-compatible object as a log destination. Multiple outputs can be registered; each message is written to all of them. Call this in `setup()` after initializing the target object. ```APIDOC ## `forwardTo` — Register a log output Registers any `Print`-compatible object as a log destination. Multiple outputs can be registered; each message is written to all of them. Call this in `setup()` after initializing the target object. ```cpp #include #include #include Mycila::Logger logger; StreamString logBuffer; // in-memory capture buffer void setup() { Serial.begin(115200); while (!Serial) continue; // Forward to hardware serial logger.forwardTo(&Serial); // Also forward to an in-memory StreamString buffer logger.forwardTo(&logBuffer); logger.info("APP", "Logger initialized with %d outputs", 2); // Read back what was captured in the buffer Serial.println("Buffer contents: " + logBuffer); logBuffer.clear(); } ``` ``` -------------------------------- ### redirectArduinoLogs Source: https://context7.com/mathieucarbou/mycilalogger/llms.txt Installs a low-level character hook so that all output from Arduino's log macros (and any ESP-IDF subsystem) is captured and forwarded through the Mycila::Logger outputs instead of going directly to UART. ```APIDOC ## redirectArduinoLogs ### Description Captures Arduino / ESP-IDF system logs by installing a low-level character hook. All output from Arduino's `log_d`, `log_i`, `log_w`, `log_e` macros (and any ESP-IDF subsystem) is captured and forwarded through the `Mycila::Logger` outputs instead of going directly to UART. ### Method `static void redirectArduinoLogs(Mycila::Logger& logger)` ### Example ```cpp #include #include #include Mycila::Logger logger; StreamString logBuffer; void setup() { Serial.begin(115200); while (!Serial) continue; // Redirect Arduino/ESP-IDF logs into our logger pipeline Mycila::Logger::redirectArduinoLogs(logger); // or, on an instance: logger.redirectArduinoLogs(); logger.setLevel(ARDUHAL_LOG_LEVEL_DEBUG); logger.forwardTo(&logBuffer); // These standard Arduino macros now flow through MycilaLogger log_d("Arduino debug message"); log_i("Arduino info message"); log_w("Arduino warning message"); log_e("Arduino error message"); Serial.println("Captured Arduino logs:"); Serial.println(logBuffer); logBuffer.clear(); // Direct Mycila API calls work the same way logger.info("APP", "System ready"); Serial.println(logBuffer); } void loop() { delay(500); } ``` ``` -------------------------------- ### Redirect Arduino/ESP-IDF System Logs with `redirectArduinoLogs` Source: https://context7.com/mathieucarbou/mycilalogger/llms.txt Capture and forward all Arduino/ESP-IDF system logs through Mycila::Logger by installing a low-level character hook. This allows centralized logging management for both library calls and system messages. ```cpp #include #include #include Mycila::Logger logger; StreamString logBuffer; void setup() { Serial.begin(115200); while (!Serial) continue; // Redirect Arduino/ESP-IDF logs into our logger pipeline Mycila::Logger::redirectArduinoLogs(logger); // or, on an instance: logger.redirectArduinoLogs(); logger.setLevel(ARDUHAL_LOG_LEVEL_DEBUG); logger.forwardTo(&logBuffer); // These standard Arduino macros now flow through MycilaLogger log_d("Arduino debug message"); log_i("Arduino info message"); log_w("Arduino warning message"); log_e("Arduino error message"); Serial.println("Captured Arduino logs:"); Serial.println(logBuffer); logBuffer.clear(); // Direct Mycila API calls work the same way logger.info("APP", "System ready"); Serial.println(logBuffer); } void loop() { delay(500); } ``` -------------------------------- ### Instantiate Mycila::Logger Source: https://context7.com/mathieucarbou/mycilalogger/llms.txt Create a global instance of the Mycila::Logger class. No constructor arguments are required. ```cpp #include // Global logger instance, accessible from any translation unit Mycila::Logger logger; ``` -------------------------------- ### Instantiate a logger Source: https://context7.com/mathieucarbou/mycilalogger/llms.txt Create a global instance of the Mycila::Logger class. No constructor arguments are needed. ```APIDOC ## Instantiate a logger `Mycila::Logger` is a plain C++ class — create one instance (typically as a global) per application. No constructor arguments are required. ```cpp #include // Global logger instance, accessible from any translation unit Mycila::Logger logger; ``` ``` -------------------------------- ### Forward Logs to Multiple Outputs Source: https://context7.com/mathieucarbou/mycilalogger/llms.txt Register Print-compatible objects as log destinations. Messages are sent to all registered outputs. Ensure target objects are initialized before registration. ```cpp #include #include #include Mycila::Logger logger; StreamString logBuffer; // in-memory capture buffer void setup() { Serial.begin(115200); while (!Serial) continue; // Forward to hardware serial logger.forwardTo(&Serial); // Also forward to an in-memory StreamString buffer logger.forwardTo(&logBuffer); logger.info("APP", "Logger initialized with %d outputs", 2); // Read back what was captured in the buffer Serial.println("Buffer contents: " + logBuffer); logBuffer.clear(); } ``` -------------------------------- ### Display MycilaLogger Version with `MYCILA_LOGGER_VERSION` Source: https://context7.com/mathieucarbou/mycilalogger/llms.txt Use compile-time macros to display the full version string or perform numeric comparisons for feature detection. This is useful for conditional compilation based on library version. ```cpp #include void setup() { Serial.begin(115200); // Full version string Serial.println("MycilaLogger v" MYCILA_LOGGER_VERSION); // "MycilaLogger v3.3.0" // Individual components for numeric comparisons #if MYCILA_LOGGER_VERSION_MAJOR >= 3 Serial.println("Running on v3+ API"); #endif } ``` -------------------------------- ### Basic Logging Functions Source: https://github.com/mathieucarbou/mycilalogger/blob/main/docs/index.md Utilize various logging levels (debug, info, warn, error) to record messages. Includes a check for debug level enablement. ```c++ logger.debug(TAG, "Published in %u ms", (millis() - start)); logger.info(TAG, "Published in %u ms", (millis() - start)); logger.warn(TAG, "Published in %u ms", (millis() - start)); logger.error(TAG, "Published in %u ms", (millis() - start)); ``` ```c++ if(logger.isDebugEnabled()) { // some expensive debug code } ``` -------------------------------- ### Configure MycilaLogger Build Flags in `platformio.ini` Source: https://context7.com/mathieucarbou/mycilalogger/llms.txt Control MycilaLogger's behavior at compile time using preprocessor flags in `platformio.ini`. Options include setting the core debug level, enabling ANSI color codes, and customizing buffer sizes. ```ini ; platformio.ini example [env:esp32dev] platform = espressif32 board = esp32dev framework = arduino build_flags = ; Set log level (NONE=0, ERROR=1, WARN=2, INFO=3, DEBUG=4, VERBOSE=5) -D CORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_DEBUG ; Enable ANSI color codes in log output (useful with colored serial monitors) -D CONFIG_ARDUHAL_LOG_COLORS ; Override internal per-message buffer (default 256 bytes) -D MYCILA_LOGGER_BUFFER_SIZE=512 ; Use ARDUHAL_LOG_LEVEL as the dynamic level source instead of the ; internal _level field (enables runtime level changes via sdkconfig) ; -D MYCILA_LOGGER_CUSTOM_LEVEL ``` -------------------------------- ### `debug` / `info` / `warn` / `error` — Emit a log message Source: https://context7.com/mathieucarbou/mycilalogger/llms.txt The four primary logging methods accept a tag string and a `printf`-style format string with variadic arguments. Output format: `[][][][][] `. ```APIDOC ## `debug` / `info` / `warn` / `error` — Emit a log message The four primary logging methods accept a tag string and a `printf`-style format string with variadic arguments. Output format: `[][][][][] `. ```cpp #include #include #define TAG "SENSOR" Mycila::Logger logger; void readSensor() { uint32_t start = millis(); float temperature = 23.7f; int retries = 0; logger.debug(TAG, "Reading sensor (attempt %d)", retries + 1); if (temperature > 100.0f) { logger.error(TAG, "Temperature %.1f°C exceeds safety limit!", temperature); return; } if (temperature > 80.0f) { logger.warn(TAG, "Temperature %.1f°C is high", temperature); } logger.info(TAG, "Temperature: %.1f°C, read in %u ms", temperature, millis() - start); // Example output: // [ 12345][I][SENSOR][0][loopTask] Temperature: 23.7°C, read in 2 ms } void setup() { Serial.begin(115200); logger.forwardTo(&Serial); logger.setLevel(ARDUHAL_LOG_LEVEL_DEBUG); } void loop() { readSensor(); delay(2000); } ``` ``` -------------------------------- ### Access Registered Outputs with `getOutputs` Source: https://context7.com/mathieucarbou/mycilalogger/llms.txt Retrieve a reference to the internal list of registered `Print*` outputs. This allows runtime inspection, iteration, or removal of logging destinations. ```cpp #include Mycila::Logger logger; void setup() { Serial.begin(115200); logger.forwardTo(&Serial); auto& outputs = logger.getOutputs(); Serial.printf("Registered outputs: %u\n", outputs.size()); // 1 // Remove all outputs to silence the logger temporarily outputs.clear(); logger.info("APP", "This message goes nowhere"); // Re-add Serial logger.forwardTo(&Serial); logger.info("APP", "Logging restored"); } ``` -------------------------------- ### Emit Log Messages with debug/info/warn/error Source: https://context7.com/mathieucarbou/mycilalogger/llms.txt Use these methods to log messages with a tag and printf-style formatting. Output includes timestamp, level, tag, core, and task name. ```cpp #include #include #define TAG "SENSOR" Mycila::Logger logger; void readSensor() { uint32_t start = millis(); float temperature = 23.7f; int retries = 0; logger.debug(TAG, "Reading sensor (attempt %d)", retries + 1); if (temperature > 100.0f) { logger.error(TAG, "Temperature %.1f°C exceeds safety limit!", temperature); return; } if (temperature > 80.0f) { logger.warn(TAG, "Temperature %.1f°C is high", temperature); } logger.info(TAG, "Temperature: %.1f°C, read in %u ms", temperature, millis() - start); // Example output: // [ 12345][I][SENSOR][0][loopTask] Temperature: 23.7°C, read in 2 ms } void setup() { Serial.begin(115200); logger.forwardTo(&Serial); logger.setLevel(ARDUHAL_LOG_LEVEL_DEBUG); } void loop() { readSensor(); delay(2000); } ``` -------------------------------- ### Log Messages Source: https://github.com/mathieucarbou/mycilalogger/blob/main/README.md Use various logging levels (debug, info, warn, error) to record messages. Includes a check for debug level enablement. ```c++ logger.debug(TAG, "Published in %u ms", (millis() - start)); logger.info(TAG, "Published in %u ms", (millis() - start)); logger.warn(TAG, "Published in %u ms", (millis() - start)); logger.error(TAG, "Published in %u ms", (millis() - start)); if(logger.isDebugEnabled()) { // some expensive debug code } ``` -------------------------------- ### Control Log Verbosity with setLevel/getLevel Source: https://context7.com/mathieucarbou/mycilalogger/llms.txt Set the minimum log level using ARDUHAL_LOG_LEVEL constants. Messages below this level are dropped. This keeps hot paths efficient. ```cpp #include Mycila::Logger logger; void setup() { Serial.begin(115200); logger.forwardTo(&Serial); // Enable all levels including debug logger.setLevel(ARDUHAL_LOG_LEVEL_DEBUG); Serial.printf("Current level: %u\n", logger.getLevel()); // 4 logger.debug("CFG", "Debug is now active"); // Raise threshold to warnings and above logger.setLevel(ARDUHAL_LOG_LEVEL_WARN); logger.debug("CFG", "This message is suppressed"); logger.warn("CFG", "This warning is printed"); } ``` -------------------------------- ### `setLevel` / `getLevel` — Control log verbosity Source: https://context7.com/mathieucarbou/mycilalogger/llms.txt Sets the minimum log level using the standard `ARDUHAL_LOG_LEVEL_*` constants. Messages at a lower level are silently dropped before any formatting occurs, keeping hot paths cheap. ```APIDOC ## `setLevel` / `getLevel` — Control log verbosity Sets the minimum log level using the standard `ARDUHAL_LOG_LEVEL_*` constants. Messages at a lower level are silently dropped before any formatting occurs, keeping hot paths cheap. ```cpp #include Mycila::Logger logger; void setup() { Serial.begin(115200); logger.forwardTo(&Serial); // Enable all levels including debug logger.setLevel(ARDUHAL_LOG_LEVEL_DEBUG); Serial.printf("Current level: %u\n", logger.getLevel()); // 4 logger.debug("CFG", "Debug is now active"); // Raise threshold to warnings and above logger.setLevel(ARDUHAL_LOG_LEVEL_WARN); logger.debug("CFG", "This message is suppressed"); logger.warn("CFG", "This warning is printed"); } ``` ``` -------------------------------- ### getOutputs Source: https://context7.com/mathieucarbou/mycilalogger/llms.txt Returns a reference to the internal `std::vector` of registered outputs. Use this to iterate over, inspect, or remove outputs at runtime. ```APIDOC ## getOutputs ### Description Access the registered output list. Returns a reference to the internal `std::vector` of registered outputs. Use this to iterate over, inspect, or remove outputs at runtime. ### Method `std::vector& getOutputs()` ### Example ```cpp #include Mycila::Logger logger; void setup() { Serial.begin(115200); logger.forwardTo(&Serial); auto& outputs = logger.getOutputs(); Serial.printf("Registered outputs: %u\n", outputs.size()); // 1 // Remove all outputs to silence the logger temporarily outputs.clear(); logger.info("APP", "This message goes nowhere"); // Re-add Serial logger.forwardTo(&Serial); logger.info("APP", "Logging restored"); } ``` ``` -------------------------------- ### isDebugEnabled Source: https://context7.com/mathieucarbou/mycilalogger/llms.txt Returns true when the current log level includes debug messages. Use this to skip costly string construction or computation that is only relevant during debugging. ```APIDOC ## isDebugEnabled ### Description Returns `true` when the current log level includes debug messages. Use this to skip costly string construction or computation that is only relevant during debugging. ### Method `bool isDebugEnabled()` ### Example ```cpp #include Mycila::Logger logger; void processData(const uint8_t* data, size_t len) { if (logger.isDebugEnabled()) { // Build a hex dump only when debug output is active String hex; hex.reserve(len * 3); for (size_t i = 0; i < len; i++) { char buf[4]; snprintf(buf, sizeof(buf), "%02X ", data[i]); hex += buf; } logger.debug("DATA", "Raw bytes (%u): %s", len, hex.c_str()); } } ``` ``` -------------------------------- ### Guard Expensive Debug Operations with `isDebugEnabled` Source: https://context7.com/mathieucarbou/mycilalogger/llms.txt Use `isDebugEnabled` to conditionally execute code that is only relevant for debugging. This prevents costly operations like string construction when debug logging is not active. ```cpp #include Mycila::Logger logger; void processData(const uint8_t* data, size_t len) { if (logger.isDebugEnabled()) { // Build a hex dump only when debug output is active String hex; hex.reserve(len * 3); for (size_t i = 0; i < len; i++) { char buf[4]; snprintf(buf, sizeof(buf), "%02X ", data[i]); hex += buf; } logger.debug("DATA", "Raw bytes (%u): %s", len, hex.c_str()); } } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.