17
17
18
18
#define LogRotationDepth 5
19
19
20
- #define FlushInterval_us 50000
20
+ #define FlushInterval_ms 500
21
21
22
22
#define logFilename "xblast.log"
23
23
static const char * const ActiveLogFileLocation = PathSep "MASTER_X" PathSep logFilename ;
@@ -31,7 +31,7 @@ static unsigned int cursorInBuf = 0;
31
31
32
32
static void processTempBuf (void );
33
33
static void stringFormat (const char * const debugFlag , unsigned char logLevel , const char * const functionName , const char * const buffer , const va_list * vargs );
34
- static void writeString (const char * const string , unsigned char writeToLogFile );
34
+ static void writeString (const char * const string , unsigned char writeToLogFile , unsigned char spiPrintOnly );
35
35
static void put (unsigned char writeToFile , const char * const string );
36
36
static unsigned char assertWriteToFile (const char * const szDebugFlag , unsigned char flushLogFlag );
37
37
static const char * const getLogLevelString (unsigned char logLevel );
@@ -41,9 +41,9 @@ void debugLoggerInit(void)
41
41
activeLogHandle .obj .fs = NULL ;
42
42
if (0 == logRotate ())
43
43
{
44
- processTempBuf ();
45
- newCallbackTimer (& forceFlushLog , FlushInterval_us );
46
44
initDone = 1 ;
45
+ processTempBuf ();
46
+ newCallbackTimer (& forceFlushLog , FlushInterval_ms );
47
47
}
48
48
}
49
49
@@ -80,7 +80,7 @@ unsigned char logRotate(void)
80
80
XBlastLogger (DEBUG_LOGGER , DBG_LVL_DEBUG , "Open:%s." , ActiveLogFileLocation );
81
81
if (FR_OK != result )
82
82
{
83
- XBlastLogger (DEBUG_LOGGER , DBG_LVL_ERROR , "Couldn't open log file." );
83
+ XBlastLogger (DEBUG_LOGGER , DBG_LVL_ERROR | DBG_FLG_SPI , "Couldn't open log file." );
84
84
return 1 ;
85
85
}
86
86
@@ -158,16 +158,17 @@ static void processTempBuf(void)
158
158
159
159
if (initDone )
160
160
{
161
- XBlastLogger (DEBUG_LOGGER , DBG_LVL_INFO , "Dumping temp log buffer. len:%u" , cursorInBuf );
161
+ XBlastLogger (DEBUG_LOGGER , DBG_LVL_DEBUG | DBG_FLG_SPI , "Dumping temp log buffer. len:%u" , cursorInBuf );
162
162
writeCount = f_puts (tempBufBeforeHDDInit , & activeLogHandle );
163
- XBlastLogger (DEBUG_LOGGER , DBG_LVL_DEBUG , "puts writeCount:%u" , writeCount );
163
+ XBlastLogger (DEBUG_LOGGER , DBG_LVL_DEBUG | DBG_FLG_SPI , "puts writeCount:%u" , writeCount );
164
164
165
- if (cursorInBuf != writeCount )
165
+ if (cursorInBuf > writeCount )
166
166
{
167
- XBlastLogger (DEBUG_LOGGER , DBG_LVL_FATAL , "Temp log dump error:%u" , writeCount );
167
+ XBlastLogger (DEBUG_LOGGER , DBG_LVL_FATAL | DBG_FLG_SPI , "Temp log dump error:%u" , writeCount );
168
168
}
169
169
170
170
}
171
+ * tempBufBeforeHDDInit = '\0' ;
171
172
cursorInBuf = 0 ;
172
173
}
173
174
@@ -177,29 +178,33 @@ static void stringFormat(const char* const debugFlag, unsigned char logLevel, co
177
178
char tempBuf [1024 ];
178
179
unsigned char writeToLogfile ;
179
180
unsigned char flushToLogFile = logLevel & DBG_FLG_DUMP ;
180
- logLevel &= ~((unsigned char )DBG_FLG_DUMP );
181
+ unsigned char spiPrintOnly = logLevel & DBG_FLG_SPI ;
182
+ logLevel &= ~((unsigned char )DBG_FLG_DUMP | DBG_FLG_SPI );
181
183
182
184
writeToLogfile = assertWriteToFile (debugFlag , flushToLogFile );
183
- sprintf (tempBuf , "[%s][%s][%s] " , getLogLevelString (logLevel ), debugFlag , functionName );
184
- writeString (tempBuf , writeToLogfile );
185
+ sprintf (tempBuf , "[%u][% s][%s][%s] " , getMS () , getLogLevelString (logLevel ), debugFlag , functionName );
186
+ writeString (tempBuf , writeToLogfile , spiPrintOnly );
185
187
vsprintf (tempBuf ,buffer , * vargs );
186
- writeString (tempBuf , writeToLogfile );
188
+ writeString (tempBuf , writeToLogfile , spiPrintOnly );
187
189
188
190
if ('\n' != tempBuf [strlen (tempBuf ) - 1 ])
189
191
{
190
- writeString ("\n" , writeToLogfile );
192
+ writeString ("\n" , writeToLogfile , spiPrintOnly );
191
193
}
192
194
}
193
195
194
- static void writeString (const char * const string , unsigned char writeToLogFile )
196
+ static void writeString (const char * const string , unsigned char writeToLogFile , unsigned char spiPrintOnly )
195
197
{
196
198
FRESULT result ;
197
199
/* write to SPI debugger, if applicable */
198
200
#ifdef SPITRACE
199
201
printTextSPI (string );
200
202
#endif
201
203
/* Write to log file*/
202
- put (writeToLogFile , string );
204
+ if (0 == spiPrintOnly )
205
+ {
206
+ put (writeToLogFile , string );
207
+ }
203
208
}
204
209
205
210
static void put (unsigned char writeToFile , const char * const string )
0 commit comments