ArduinoLog Cheat Sheet

A Programming › C cheat sheet in English by TimoFran

Cheatsheet for ArduinoLog library

2,514 views 465 downloads 15 Nov 2023 History

Variables

%s
string (char*)
%S
string from flash memory (char[] PROGMEM)
%c
single character
%C
signel character (hex if not printable)
%d
integer
%l
long
%u
unsigned long
%x
hexade­cimal
%X
hexade­cimal (0x prefix) and leading zeros
%b
binary number
%B
binary number (0b prefix)
%t
boolean '­t' or '­f'
%T
boolean '­tru­e' or '­fal­se'
%D, %F
double
%p
printable object
Example: Log.no­tic­e("T­emp­era­ture: %D", temp_c);

Initia­liz­ation

Serial.begin(9600);
    
// Initialize with log level and log output. 
Log.begin   (LOG_giLEVEL_VERBOSE, &Serial);

Log leveles

LOG_LE­VEL­_SILENT
no output
LOG_LE­VEL­_FATAL
fatal errors
LOG_LE­VEL­_ERROR
all errors
LOG_LE­VEL­_WA­RNING
errors and warnings
LOG_LE­VEL­_NOTICE
errors, warnings and notices
LOG_LE­VEL­_TRACE
errors, warnings, notices and traces
LOG_LE­VEL­_VE­RBOSE
all

Disable library

Uncomment #define DISABL­E_L­OGGING in Logging.h
This may signif­icantly reduce your project size.

Custom logging format

Log.setPrefix(printPrefix);
Log.setSuffix(printSuffix);
Log.notice("Message to be logged");

void printPrefix(Print* _logOutput, int logLevel) {
    _logOutput->print("00:47:51.432 ");
}

void printSuffix(Print* _logOutput, int logLevel) {
     _logOutput->print(".");
}
Result:
00:47:­51.432 Message to be logged.

Comments

No comments yet.

Cheatography n. The art of mapping complex subjects into clear, instantly navigable reference guides.