Last active
February 17, 2016 20:49
-
-
Save justbuchanan/7eb692b3e7ba946b2698 to your computer and use it in GitHub Desktop.
Stream-based logging test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <string> | |
#include <sstream> | |
using namespace std; | |
class LogHelper : public stringstream { | |
public: | |
LogHelper(string level) { | |
*this << "[" << level << "] "; | |
} | |
~LogHelper() { | |
// TODO: lock | |
printf("%s\n", str().c_str()); | |
// TODO: unlock | |
} | |
}; | |
#define LOG(level) LogHelper(level) | |
int main(int argc, char** argv) { | |
LOG("INIT") << "init text"; | |
LOG("ERROR") << "error text"; | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
all: main | |
main: main.cpp | |
clang++ -g -std=c++11 -o main main.cpp | |
run: main | |
./main |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment