Skip to content

Utilizing the Loom Logger

Will Richards edited this page Sep 2, 2023 · 1 revision
Author: Will Richards

The Loom logging framework is setup to allow for easy debugging over long-term deployments where being connected to the Serial monitor the entire time isn't an option. In addition the Loom logger also supports "function summaries", These currently provide a view of the function execution order, total memory usage and runtime. This output makes finding and diagnosing memory leaks much easier.

Enabling Features

By default the logger is NOT setup to log to an SD card or Generate function summaries

To enable logging to an SD card a Hypnos must be constructed in the sketch, these lines can then be added as shown to your sketch

void setup() { // This will already be in your sketch so don't copy this part

  /* Enables logging logs to the SD card for later viewing under the 'debug' folder */
  ENABLE_SD_LOGGING;   
  
  /* Enables generation of function summaries */
  ENABLE_FUNC_SUMMARIES;
Logging Macros

Each log type supports standard hardcoded strings as well as flash strings designated with an F(), with the exception of LOG_LONG these each have a max total message length of 255 characters.

LOG(msg); - This is a standard information log 
	LOG(F("Successfully Initialized!")); ->
		[2023.09.02 05:33:44] [DEBUG] [Loom_MS5803.cpp:initialize:22] Successfully Initialized!

ERROR(msg); - This is a standard error log
	ERROR(F("Failed to initialize sensor!")); ->
		[2023.09.02 05:33:19] [ERROR] [Loom_MS5803.cpp:initialize:18] Failed to initialize sensor!

WARNING(msg); - This is a standard warning log
	WARNING(F("RTC lost power, lets set the time!")); ->
		[2023.09.02 05:33:22] [WARNING] [Loom_Hypnos.cpp:initializeRTC:163] RTC lost power, let's set the time!

// Advanced Logging Macros (Helper Methods)
SLOG (msg); - This is a silent log and will only log the information to the SD card without printing to the Serial monitor
	SLOG("measure") ->
		[2023.09.02 05:33:22] [DEBUG] [src/Logger.h:startFunction:233] measure
	
LOG_LONG(msg); - This takes a longer char array and writes only it to the SD card no log formatting
	char str[2000]
	LOG_LONG(str); -> 
		{
		  "type": "data",
		  "id": {
		    "name": "Chime",
		    "instance": 3
		  },
		  "contents": [
		    {
		      "module": "Packet",
		      "data": {
		        "Number": 1
		      }
		    },
		    {
		      "module": "Analog",
		      "data": {
		        "Vbat": 4.303857327,
		        "Vbat_MV": 4302.246094
		      }
		    },
		...

Each piece comes together to create a log file that looks like this... Pasted image 20230902063455

Function Summaries

Function summaries are autogenerated when ENABLE_FUNC_SUMMARIES; has been called

FUNCTION_START; - This designates the beginning of a function to the logger.
FUNCTON_END; - This designates the end of a function to the logger.

The addition of these two commands at the start and end of functions results in a summary file that looks like this... Pasted image 20230902065118

The Sidebar :)

Getting Started

Backend Server

Contributing

Style Guide

Clone this wiki locally