logog
logger optimized for games
|
The Formatter object is responsible for rendering a particular Topic into a human-readable format. A default Formatter is created by default for you based on the flavor of the compile target. See FormatterGCC and FormatterMSVC objects for examples.
If you want log messages in your own custom format, subclass the Formatter::Format method into your own custom class, and write your own formatting function for a topic. See FormatterMSVC::Format and FormatterGCC::Format for examples.
Once you have written your own custom formatting function, assign it to the Target that should use your custom formatter, by using the Target::SetFormatter() function.
If all you want to do is enable or disable a certain type of output on your formatter – for example, to remove file and line number information from all your output lines – then there's a very simple way of doing this. The Formatter class implements a Formatter::GetTopicFlags() function that in the default case queries the topic in order to find out which fields to render. You can if you wish override this default behavior for a custom formatter in order to always or never render specific fields.
The following example overrides the standard FormatterMSVC formatter in order to never show file and line number information on the output.
If you wish, you can force a formatter to output the current date and time as part of their format. You can do this by calling the Formatter::SetShowTimeOfDay function with a value of true, as follows:
Here's a more general example of doing radical custom changes to the formatting style of the output. In this case, the formatter adds exclamation mark boundaries to any message of LOGOG_LEVEL_WARN type or more important, and it adds three periods to the end of any message. Since this custom formatter only applies to the target set with Target::SetFormatter(), you could modify this example and the changes would only apply to the formatter you select.