Skip to content

Instantly share code, notes, and snippets.

@justbuchanan
Last active February 17, 2016 20:49
Show Gist options
  • Save justbuchanan/7eb692b3e7ba946b2698 to your computer and use it in GitHub Desktop.
Save justbuchanan/7eb692b3e7ba946b2698 to your computer and use it in GitHub Desktop.
Stream-based logging test
#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;
}
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