Using LogHandler to log to an SD Card with SdFat library

I am trying to create/adapt my own LogHandler to log to an SD card using the SdFat library. I have taken inspiration from the Papertrial LogHandler, as C++ is not my first language…

A few issues/questions have come up, and I was hoping for some guidance/thoughts/ideas.

Inheritance questions for inputs

Assume I’ve created a new class which starts out something like this:

class SdLogHandler : public LogHandler {
    String m_system;

    public SdLogHandler(String system = System.deviceID(), LogLevel level = LOG_LEVEL_INFO, const LogCategoryFilters &filters = {});
    virtual ~SdLogHandler();

...
}

When I try to use the same inputs as used in the SerialLogHandler example (with loglevels and filters), I get the error: “no matching function for call to ‘SdLogHandler::SdLogHandler(LogLevel)’”. Why is this the case?

Alternatives to Global Variables

To enable the use of the SdFat library for SD use across multiple files, I set the instance of SdFat as a global variable. Is there a better way to do this? Is it possible to create multiple instances of SdFat for use on 1 SD Card? I plan to use the same SD card for logging data and info/bugs…

Any recommendations are greatly appreciated. I can also update with more code if helpful.

Default parameters can only be omitted from the end forward, but in your case you want to provide the middle paramter and omit the first and last - that is not allowed in C++.

To do what you want you need to have a seperate constructor (overload) that takes the log level as first (or only) parameter.

1 Like