I am reorganizing my C ++ application. Before I used a macro like
LOG("something interesting") // 1 LOG("something ended") // 2 LOG("foo: " << bar) // 3
Now my idea was to write a Log class:
Log(std::string _init_message): init_message(_init_message) { PrintLogLine(init_message + " ...");} ~Log() { PrintLogLine(init_message + " done.");}
to get "automatic" logging of certain actions (i.e. when they start, stop + additional timings, etc.) when I use it like
void ActionXYZ() { Log log("xyz");
Where I struggle is the definition of a way to make it work in case 3). In Java, I could use a method that takes a single String argument, since the compiler takes care of automatically building the string. What features do I have in C ++?
Can I make it work so that I can use it as one of the options?
// in "do stuff" log("foo:" + bar); // OR log << "foo:" << bar;
source share