Quantcast
Channel: Active questions tagged gcc - Stack Overflow
Viewing all articles
Browse latest Browse all 22299

Stripping out static text from log messages and save only variables [closed]

$
0
0

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:

  1. 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>
  1. 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:

messages_array

  1. 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?


Viewing all articles
Browse latest Browse all 22299

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>