Declare module name of classes for logging
Posted
by Space_C0wb0y
on Stack Overflow
See other posts from Stack Overflow
or by Space_C0wb0y
Published on 2010-03-25T09:43:19Z
Indexed on
2010/03/25
11:33 UTC
Read the original article
Hit count: 321
I currently am adding some features to our logging-library. One of these is the possibility to declare a module-name for a class that automatically gets preprended to any log-messages writing from within that class. However, if no module-name is provided, nothing is prepended. Currently I am using a trait-class that has a static function that returns the name.
template< class T >
struct ModuleNameTrait {
static std::string Value() { return ""; }
};
template< >
struct ModuleNameTrait< Foo > {
static std::string Value() { return "Foo"; }
};
This class can be defined using a helper-macro. The drawback is, that the module-name has to be declared outside of the class. I would like this to be possible within the class. Also, I want to be able to remove all logging-code using a preprocessor directive. I know that using SFINAE one can check if a template argument has a certain member, but since other people, that are not as friendly with templates as I am, will have to maintain the code, I am looking for a much simpler solution. If there is none, I will stick with the traits approach.
Thanks in advance!
© Stack Overflow or respective owner