Skip to content
This repository has been archived by the owner on Oct 9, 2023. It is now read-only.

Improve log messages header generation #183

Open
qdeslandes opened this issue Nov 29, 2018 · 0 comments
Open

Improve log messages header generation #183

qdeslandes opened this issue Nov 29, 2018 · 0 comments

Comments

@qdeslandes
Copy link
Owner

Is your feature request related to a problem? Please describe.

Due du the fact user can customize log messages header (with the time, the subsystem ...), yall contains a mechanism used to match the use defined header pattern and the different message parameters. This mechanism should be as efficient as possible as it will be called at each log message.

This mechanism works the following way:

  • When customizing the messages header, an array for the modifier will be created. This array will store, at each index, the type of the modifier (subsystem name, time...) in order.
  • When a log message has to be printed, an array with the different parameters value is created (log level, subsystem name, time...) in a specific order too.
  • Once we call snprintf() to generate the log message, a set of parameters are given to the function, in a very messy way, and the one displayed (printed in the string) is the one matching the proper type for a given index.
wrote = (size_t)snprintf(buffer, len, hdr, ordered_content[matches[0]],
	ordered_content[matches[1]], ordered_content[matches[2]],
	ordered_content[matches[3]], ordered_content[matches[4]],
	ordered_content[matches[5]], ordered_content[matches[6]],
	ordered_content[matches[7]], ordered_content[matches[8]],
	ordered_content[matches[9]]);

ordered_content stores all the strings containing the log message line, the function, the subsystem name... And matches stores the different modifiers types to display in the log message.

This solution is very messy and does not handle cases where more than 10 modifiers are used (even if currently, less than 10 modifiers does exists). But it's the most efficient solution.

Describe the solution you'd like

?

Describe alternatives you've considered

N/A

Additional context

N/A

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

1 participant