SerialLogHandler vs. Serial.print


#1

Hi Everyone!

I just discovered the logging classes that are available after a long time of just using Serial.print statements to output info from my application.

I was just curious… is there any pros or cons of using the logging functions over serial.print that we should know about? Is there best practice people use for using one vs. the other?

Thanks!


#2

One thing is granularity.
You can easily filter for different log levels by just instantiating a log handler for the desired level without cumbersome if/#ifdef constructs.
You can also target different channels than just Serial by instantiating a different handler (e.g. UDP, TCP, Serial1, …)


#3

Just beware that I have found some weird behaviour with the Log class that actually causes Kernel panic, whereas a Seriial.printf() in the exact same code position works fine.

Am yet to find an explanation for this.

That said, logging is the way to go, especially now with the addition of USBSeriial1. Associate the Logger class with this port and it frees up Serial for application use rather than debugging.


#4

Update to my kernel panics for logging within some routines. The issue was within routines called within a timer callback. So beware!