SdCardLogHandlerRK
|
Class for writing a data stream to SD card. More...
#include <SdCardLogHandlerRK.h>
Public Member Functions | |
SdCardPrintHandler (SdFat &sd, uint8_t csPin, uint8_t divisor) | |
SdCardPrintHandler & | withLogsDirName (const char *value) |
Sets the log directory name. Default: "logs". More... | |
SdCardPrintHandler & | withDesiredFileSize (size_t value) |
Desired file size in bytes. Default: 1000000 bytes (1 MB) More... | |
SdCardPrintHandler & | withMaxFilesToKeep (size_t value) |
The number of files to keep. Default: 10. More... | |
SdCardPrintHandler & | withCardCheckPeriod (unsigned long value) |
The number of milliseconds to between checks to see if the SD card is present. Default: 10000. More... | |
SdCardPrintHandler & | withSyncEveryEntry (size_t value) |
Set whether to sync the file system after every log entry. Default: true. More... | |
SdCardPrintHandler & | withNoSerialLogging () |
The default is to log to Serial as well as SD card; to only log to SD card call this method. More... | |
SdCardPrintHandler & | withWriteToStream (Stream *value) |
Write to a different Stream, such as Serial1. Default: Serial. More... | |
virtual size_t | write (uint8_t) |
Virtual override for the StreamLogHandler to write data to the log. | |
bool | getLastBeginResult () const |
Checks the result of the last time sd.begin() was called. More... | |
Class for writing a data stream to SD card.
You normally instantiate one of these as a global variable, passing in the SdFat object and the parameters you'd normally pass to SdFat::begin().
You can pass additional options using the fluent-style methods beginning with "with" like withLogsDirName().
This class is a subclass of Print, so you can use all of the overloads of print, println, and printf that are supported by Print. Data is buffered until the
, then written to the card, for performance reasons and to avoid splitting a line between multiple files.
|
inline |
Checks the result of the last time sd.begin() was called.
This call determines whether the last call to sd.begin() succeeded or not. You might do this if you also need to call SdFat from your own code. This library needs to call sd.begin() internally to do it very early, and also after the SD card is ejected.
|
inline |
The number of milliseconds to between checks to see if the SD card is present. Default: 10000.
When you remove the SD card, it's necessary to reinitialize the SdFat library and check for the card. Because of timeouts, this takes a while, so logging would become very slow if every attempt to log caused this delay. The card check period reduces the frequency of checking to see if a card has been inserted.
Note that as long as you leave the card in, you won't experience this.
value | The time in milliseconds (unsigned ling) |
|
inline |
Desired file size in bytes. Default: 1000000 bytes (1 MB)
Each log file will be approximately this size. It typically will be slightly larger than this, as the log is rotated when the size is exceeded. If changed, it will only be enforced for the current log file; old log files are not modified.
value | The maximum file size for a log file in bytes (size_t) |
|
inline |
Sets the log directory name. Default: "logs".
The logs must always be in a subdirectory, so make sure you set it to something, setting it to an empty string or NULL will disable logging.
value | The name to use instead of "logs" (const char *). This is not copied, as a constant string is normally passed in. If you calculate it, make sure you put it in a static or allocated buffer! |
|
inline |
The number of files to keep. Default: 10.
The maximum number of log files to keep is enforced at startup, when a SD card is inserted, and when the current log file is full.
value | Number of files to kee. Values are 1 <= num <= 999999 (size_t) |
|
inline |
The default is to log to Serial as well as SD card; to only log to SD card call this method.
If you want to log to a different stream (like Serial1), use withWriteToStream() instead.
|
inline |
Set whether to sync the file system after every log entry. Default: true.
Setting this to false dramatically improves the performance, but it also makes it much more likely that in the case of a reboot, the last log messages will be lost. The SdFat library normally only flushes the file in 512 byte increments so if you log infrequently, you could lose a number of log messages.
value | The value to set (size_t) |
|
inline |
Write to a different Stream, such as Serial1. Default: Serial.
value | The stream to write log output to (such as &Serial1) or NULL to only write to the SD card. |
Only one stream is supported. Setting it again replaces the last setting.