I like to have the name of the current method for logging purposes. For example:
string Commands::test(StringTokenizer& tokens)
{
static string src("Commands::test");
...
_log.debug("message", src);
}
I'm worried that creating 'src' might cause a performance hit. I made the string static thinking it would only be constructed once, the first time it is used and from then on, it would be available.
Am I correct in thinking that 'static string src' will only be constructed once and then be available instantly from then on? Is there a better way to force 'src' to be created once and remain in memory somewhere and be persistently available?
PS: I would like for 'src' to be a local variable because it's easy to initialize it there. Trying to handle it as a class property or somewhere else seems to get messy.
I would very much appreciate any suggestions!
Todd