A system Logger Library for the ESP micro controller chips
The footprint is about 40k of program storage space and 2.4k of dynamic memory.
You need to include "ESP_SysLogger.h"
#include "ESP_SysLogger.h"
Then you need to create the ESPSL object
ESPSL sysLog;
In setup()
add the following code to create or open a log file of 100 lines, 80 chars/line
SPIFFS.begin();
.
.
if (!sysLog.begin(100, 80)) {
Serial.println("sysLog.begin() error!");
delay(10000);
}
Adding an entry to the system log
sysLog.write("This is a line of text");
or
sysLog.writef("This is line [%d] of [%s]", __LINE__, __FUNCTION__);
To display the sytem log file you first have to tell the ESP_SysLogger where to start and how many lines you want to see
Serial.println("\n=====from oldest to end==============================");
sysLog.startReading(0, 0);
while( (lLine = sysLog.readNextLine()) && !(lLine == "EOF")) {
Serial.printf("==>> [%s]\r\n", lLine.c_str());
}
or just the last 15 lines
Serial.println("\n=====last 15 lines==============================");
sysLog.startReading(-15);
while( (lLine = sysLog.readNextLine()) && !(lLine == "EOF")) {
Serial.printf("==>> [%s]\r\n", lLine.c_str());
}
With a simple macro you can add Debug info to your log-lines
/* example of debug info with time information ----------------------------------------------*/
#define writeToSysLog(...) ({ sysLog.writeDbg(sysLog.buildD("[%02d:%02d:%02d][%-12.12s] " \
, hour(), minute(), second() \
, __FUNCTION__) \
,__VA_ARGS__); })
or
/* example of debug info with calling function and line in calling function -----------------*/
#define writeToSysLog(...) ({ sysLog.writeDbg(sysLog.buildD("[%-12.12s(%4d)] " \
, __FUNCTION__, __LINE__) \
,__VA_ARGS__); })
This Logline:
writeToSysLog("Reset Reason [%s]", ESP.getResetReason().c_str());
looks like this wth the first writeToSysLog() example (the first line):
[12:30:22][setup ] Reset Reason [External System]
the macro add's the time, and the function-name that called this writeToSysLog() macro
[12:30:22][setup ] <rest of the log text>
Opens an existing system logfile. If there is no system logfile
it will create one with depth lines each lineWidth chars wide.
The max. lineWidth is 150 chars
Return boolean. true if succeeded, otherwise false
if mode is true:
It will create a new system logfile with depth lines each lineWidth chars wide.
if mode is false:
Opens an existing system logfile. If there is no system logfile
it will create one with depth lines each lineWidth chars wide.
Return boolean. true if succeeded, otherwise false
Display some internal var's of the system logfile to Serial.
Set the debug output to serIn.
Set the debug output to serIn.
Prints the line to serIn.
Prints the line to serIn (and add a '\n' at the end)
Prints formatted line to serIn
This method will write a line of text to the system logfile.
Return boolean. true if succeeded, otherwise false
This method will write a formatted line of text to the system logfile.
The syntax is the same as printf().
Return boolean. true if succeeded, otherwise false
This method will write a formatted line of text to the system logfile but with
a string in front of it. This 'string' can be formatted using ESPSL::build().
The syntax for *fmt, ... is the same as printf().
This method is ment to be used with the writeToSysLog() macro.
Return boolean. true if succeeded, otherwise false
This method will return a formatted line of text.
The syntax for *fmt, .. is the same as printf().
This method is ment to be used to 'feed' the ESPSL:writeDbg()
method.
Return char*.
Sets the read pointer to startLine and the end pointer to
startLine + numLines.
This method should be called before using readNextLine().
Return boolean. true if succeeded, otherwise false
Sets the read pointer to startLine. If startLine is a negative
number the read pointer will be set to startLine lines before EOF.
This method should be called before using readNextLine().
Return boolean. true if succeeded, otherwise false
Reads the next line from the system logfile and advances the read pointer one line.
Return String. Returns the next log line or EOF
This method is for debugging. It display's all the lines in the
system logfile to Serial.
Return String. Returns EOF
This methos removes a system logfile from SPIFFS.
Return boolean. true if succeeded, otherwise false
Internaly the ESP_SysLogger uses sequential lineID's to uniquely
identify each log line in the file. With this method you can query
the last used lineID.
Return uint32_t. Last used lineID.
If _DODEBUG is defines in the ESP_SysLogger.h file you can use this method to set the debug level to display specific Debug lines to Serial.
... more to come