Skip to content

Instantly share code, notes, and snippets.

@yaotti
Created August 6, 2010 07:45
Show Gist options
  • Save yaotti/511004 to your computer and use it in GitHub Desktop.
Save yaotti/511004 to your computer and use it in GitHub Desktop.
#include <string>
#include <iostream>
#include <gflags/gflags.h>
#include <glog/logging.h>
#define LINE std::cout << "------------------------------------------------------------" << std::endl;
// $ ./logging_sample -logtostderr=1
int main(int argc, char* argv[]) {
// Initialize Google's logging library.
google::InitGoogleLogging(argv[0]);
google::ParseCommandLineFlags(&argc, &argv, true);
std::cout << "START LOGGING" << std::endl;
// logging of int
int number = 10;
LOG(INFO) << "number: " << number;
// logging of int
std::string spell = "Hello, world!";
LOG(INFO) << "spell: " << spell;
LINE;
LOG(WARNING) << "log level: warning";
LOG(ERROR) << "log leve: error";
//LOG(FATAL) << "log level: fatal"; // displays backtrace and terminates the program
LINE;
LOG_IF(INFO, number > 0) << "number is greater than 0";
LINE;
VLOG(1) << "I'm printed when you run the program with --v=1 or higher";
VLOG(2) << "I'm printed when you run the program with --v=2 or higher";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment