@ScruffR, this stops the trace output (just like the documentation says it would):
SerialLogHandler logHandler(LOG_LEVEL_NONE, { // Logging level for non-application messages
{ "app", LOG_LEVEL_NONE }, // Default logging level for all application messages
{ "app.network", LOG_LEVEL_TRACE }, // Logging level for networking messages
{ "app.setup", LOG_LEVEL_WARN } // Logging level for setup messages
});
The question remains however as to how to dynamically change the logging output from a running program, eg by a cloud function. The spark_wiring_logging.h does not give an clues here.
I must admit I haven’t done that myself yet, but I’d have thought of class LogManager to be doing that.
But I’ve not checked if that is exposed to user code.
Yes, it was solved, but not quite in the that way I originally asked for (ie change the log level dynamically at will during the running of the program) because I changed my mind. I now just set it once via a config within Setup() and not change it again.
Am sure that @ScruffR’s suggestion above will work, but I did not need to make it “dynamic” in the end.
// ==== Dynamically set up logger =====
// Get log manager's instance
auto logManager = LogManager::instance();
// Configure and register log handler dynamically
LogCategoryFilters filters;
LogLevel logLevel;
// Typically set from a config - just showing what options you have here to simplify
// logLevel = LOG_LEVEL_NONE;
// logLevel = LOG_LEVEL_ERROR;
// logLevel = LOG_LEVEL_WARN;
// logLevel = LOG_LEVEL_INFO;
// logLevel = LOG_LEVEL_TRACE;
logLevel = LOG_LEVEL_ALL;
filters.append({ "app", logLevel });
// Select debug output destination
// -------------------------------
Print *pStream;
if (bUseUSBSerial1)
pStream = &USBSerial1;
else
pStream = &Serial;
auto logHandler1 = new StreamLogHandler(*pStream, LOG_LEVEL_WARN /* Default level */, filters);
logManager->addHandler(logHandler1);