The SFLOG module provides the logging system functionality to NumXL SDK, and can be used as well by your application. The logging subsystem is implemented after the common "log4j" library, and support similar configuration and functionality. The logging message contains the following:
- Timestamp
- Source File
- Line number
- Function name
- Severity
- Message
confirgurations
Upon calling the initialization API (i.e., SFLOG_INIT(.)), the calling application passes the configuration parameters as arguments:
- Basename of the log file.
- Filepath for the logfile on your systems (e.g., c:\temp)
- Log file rotation policies: Maximum filesize, compression and maximum number of files
#include <windows.h>
#include <iostream>
#include <SFLOG.h>
int main(){
string szAppName="myapp";
string szPath = "C:\\temp";
DWORD dwBackupFiles=7;
size_t ulMaxFileSize=10240,
unsigned int uClientToken=-1;
nRet =
SFLOG_INITA(szAppName.c_str(), szPath.c_str(), dwBackupFiles,ulMaxFileSize, &uClientToken);
std::cerr << "Initializing the logging facility failed, exit" << std::endl;
exit(-1);
}
.....
exit(0;)
}
#define NDK_SUCCESS
SUCCESS return code.
Definition SFLOG.h:36
#define NDK_FAILED
FAILED: Internal error occured.
Definition SFLOG.h:37
int __stdcall SFLOG_INITA(LPCSTR szAppName, LPCSTR szLogDir, DWORD dwBackupFiles, size_t ulMaxFileSize, unsigned int *pClientToken)
Initialize the logging system for SDK. This is often the first API call that an application makes and...
Definition SFLog.cpp:251
int __stdcall SFLOG_SHUTDOWN(unsigned int uClientToken)
Shutdown and release resources allocated by logging system.
Definition SFLog.cpp:296
- Note
- The logging system has two initialization API variants:
- The helper macro (SFLOG_INIT) expands during compilation to eitehr API variant based on your project Unicode settings.
- The SFLOG implements a size-based rotation for log files, so when the current log file exceed given limit, the logging system closes the file, rename it, and open a new one file for writing.
- The number of log (current + older) files reached a given limit, the logging system will delete the oldest file when it open a new file.
Log levels and Thresholds
Upon initialization, the SFLOG set the logging level or threshold to SFLOG_ERROR (or 5), by default. Thus, only log messages with severity of error or higher will be written to the log file.
To inquire about the current log level, client application should call SFLOG_GETLEVEL(), and to change the log level from its current level, client application must call SFLOG_SETLEVEL() function.
int nLevel= -1;
...
std::cerr << "Failed to query the current logging level, exit" << std::endl;
exit(-1);
}
int __stdcall SFLOG_SETLEVEL(unsigned int uClientToken, unsigned int nLevel)
set the new logging level in the SDK
Definition SFLog.cpp:431
int __stdcall SFLOG_GETLEVEL(unsigned int *nLevel)
retieve the current logging level (or threshold) in the logging system.
Definition SFLog.cpp:351
#define SFLOG_FATAL
Enable fatal or critical level logging.
Definition SFLOG.h:23
- Note
- SFLOG includes macros that capture all supported logging levels, as detailed in the following table:
Macro | Level | Description |
SFLOG_ALL | 0 | Enable all logging messages (info, debug, trace, warning and error). |
SFLOG_TRACE | 1 | Enable trace level logging: trace, debug, info, warning, error and fatal error messages. |
SFLOG_DEBUG | 2 | Enable debug level logging: debug, info, warning, error and fatal error messages. |
SFLOG_INFO | 3 | Enable information level logging: info, warning, error, and fatal error messages. |
SFLOG_WARN | 4 | Enable warning level logging: warning, error and fatal error messages. |
SFLOG_ERROR | 5 | Enable error level logging: error and fatal error messages. |
SFLOG_FATAL | 6 | Enable fatal or critical level logging. |
SFLOG_OFF | 7 | Disable all logging messages. |
Writing log messages
The client application writes to the log file by calling the SFLOG_LOGMSGA(.) for ASCII text, or SFLOG_LOGMSGW(.) for wide-charcter unicode messages. Using either variant of those two functions, the client application must provide the folllowing details:
- source filename
- Line number
- severity level
- Function name
- Error message
Just like we have for SFLOG_INIT, the SFLOG includes a helper macro SFLOG_LOGMSG that expands during compile-time to proper variant of the function based on your project's charater-set size.
Furthermore, the SFLOG system includes a set of helper macros (e.g., SFLOG_MSG_INFO, SFLOG_MSG_ERROR) to simply the logging greatly, by passing the compiler preprocessors (e.g., FILE, LINE) to many of the arguments. There is two variants of he macros: single-character (ASCII) message and wide-character (Unicode) messages.
- Note
- Having the flexibility to write ASCII/Unicode messages to the logfile frees the developer from converting string from one character-set to another, especcially, when the log messages may originat in different libraries.
Requirements
The SFLOG library is a standalone module from the rest of the NumXL SDK.
| |
Target Platform | Windows |
Header | SFLOG.h (include Windows.h) |
Library | SFLOG.lib |
DLL | SFLOG.dll |
- See also
-