Our logging module has a buffer that often gets full and we are searching for a
ID: 659114 • Letter: O
Question
Our logging module has a buffer that often gets full and we are searching for a solution to shorten our logs, without making any compormise in performance.
The code is written in C++ and currently we are using __FUNCTION__ to extract the function name for a trace, but on windows environments it also appends the whole namespace, which often represents more than half of the trace.
One of the proposed solutions was to parse the string returned by "__FUNCTION__" and extract the function name only, but we would rather not make this time performance compromise.
Another proposed solution was to #define a short function name at the beginning of every method and #undefine it at the end.
Is there any other approach for shortening (the file name in) logs on systems that have few resources?
Explanation / Answer
You could use __LINE__ instead, and although the function names will no longer be present in your logs, you can easily resolve them when analysing the logs.
An alternative is a static object in each function, declared at the start, that wraps trhe logger functions so you use it to write the log lines. The constructor would store a code (eg the line number of the declaration) that would be logged in place of the function name subsequently.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.