Duplicate Logs from system/application threads

I am currently enabling offline functionality, so implemented SYSTEM_THREAD(ENABLED) to run the offline algorithms on the application thread while the system thread deals with attempting to connect back onto WiFi in the background. We are using OS version 1.5.0.
It works well except when using the logHandler class, there are duplicate entries for many of the logs (with same timestamp). I assume this is because both system and application threads are outputting.

Here is an example output log I’m getting:
image
There are no duplicated messages when printing to Serial (using WITH_LOCK) instead of using Log.

Can someone tell me if there is a way to prevent the duplicated Log entries when using SYSTEM_THREAD(ENABLED)?

Dan, have you tried using device OS 1.4.4? I haven’t seen this problem with SYSTEM_THREAD(ENABLED);

Could you share the SerialLogHandler logHandler(); declaration you have used?

Also make sure you only declare the

SerialLogHandler logHandler;

once, in your main file. You can use Log.info() and other logging calls in other .cpp files but you should only declare one SerialLogHandler.

Thanks for the quick response.
@armor just tried v1.4. with same issue.
@rickkas7 here are my log handler calls, this might be the issue but how should we allow both Serial and SD card logging with one call?

#include "SdCardLogHandlerRK.h"

SerialLogHandler logHandler(LOG_LEVEL_INFO, {   // Logging level for non-application messages
    { "app", LOG_LEVEL_ALL },                   // Logging level for application messages
    { "app.network", LOG_LEVEL_TRACE }          // Logging level for networking messages
});
.....
SdCardLogHandler<1024> sdLogHandler(SD, chipSelect, SPI_FULL_SPEED, 
                            LOG_LEVEL_INFO, {  // Logging level for non-application messages
    { "app", LOG_LEVEL_INFO },                 // Logging level for application messages
    { "app.network", LOG_LEVEL_TRACE }         // Logging level for networking messages
});
STARTUP(sdLogHandler.withDesiredFileSize(1000000).withMaxFilesToKeep(50).withCardCheckPeriod(30000));
.....

The SdCardLogHandler defaults to logging to serial as well, which is why you are getting duplicates. To turn this off, from setup():

sdLogHandler.withNoSerialLogging();

Or you can remove the SerialLogHandler. Keeping both allows you to set the settings differently.

1 Like

Thank you @rickkas7! That works as expected.
For reference by others, I used .withNoSerialLogging() inside the STARTUP function.

On a separate note, is there a way to make the timestamp of the SD card log equal to the current time?
So that if something goes wrong, we can track back to the time it happened.