I know that there is a way to get rid of static text from log messages and keep only the variables part of the message in memory. But I am not sure exactly how it is done.
To give a concrete example to what I mean:
Here is some code for the client:
#include <stdio.h>
#include "my_logging.h"
int main() {
MY_CUSTOM_LOGGING_TECHNIQUE("This is message %d", int, 1);
MY_CUSTOM_LOGGING_TECHNIQUE("This is message %d", int, 2);
return 0;
}
And what should be done:
- During compilation/build:
Generate XML file during compilation/build to give ID for each message:
<xml>
<message params=1>
<id>123456</id>
<text>This is message %d</text>
<param>int</param>
</message>
<message params=1>
<id>456342</id>
<text>This is message %d</text>
<param>int</param>
</message>
</xml>
- During run time: only the ID of the message is stored along with values for the parameters in an appropriate structure (shown here as an array 'messages_array'): messages_array:
- During post-processing: The values saved during run-time are iterated through and combined with XML file saved during build. This post-processing step will generate the log file:
This is message 1
This is message 2
The main problem I am trying to solve here is "Not having to write static text to a file in the run-time. Instead, only the ID of the message and the value of the argument sent in the message.
So, how can I do this?