Loging to files in ILog
Loging to files is easy and simple with ILog. There is two ways you can log to a file.
-
You can pass in your own
FILE*
into theI_FS_LOG();
macro. TheI_FS_LOG();
macro takes in aFILE*
or an "std stream" like stdout, a message and then variable args (for formating the message). -
You could let ILog handle the file creation and deletion with the
I_FILE_LOG();
macro. TheI_FILE_LOG();
macro takes in a file names, a message, a mode and variable args. Most of the parameters are self explanitory except the mode parameter. The mode parameter corresponds with thefopen();
mode parameter (e.g. "w" for write, "a" for appened, etc.). To learn more about this check out this tutorial by programiz to learn more.
Code example:
#include <ILog.h>
int main()
{
I_FILE_LOG("example.log", "%d World Hello! %d", "w", 5, 6);
FILE* file;
file = fopen("example.log", "a"); // You should error check
I_FS_LOG(file, "Hello World! %d", 10);
return 0;
}
Output:
The file macros do not have debug equivlilents.