Gobelijn API documentation  - generated for commit a0cbea7
 All Classes Namespaces Files Functions Variables Typedefs Friends Macros Pages
logdemo.cpp
Go to the documentation of this file.
1 
6 #include "tclap/CmdLine.h"
7 #include "tracer/tracer.h"
8 #include <g3log/logworker.hpp>
9 
10 using namespace std;
11 
12 int main(int argc, char* argv[])
13 {
14  try {
15  // Initialize Google logging library.
16  string logPath("/tmp");
17  if (getenv("G3LOG_log_dir") != nullptr) {
18  logPath = *getenv("G3LOG_log_dir");
19  }
20  std::unique_ptr<g3::LogWorker> g3log{g3::LogWorker::createLogWorker()};
21  g3log->addDefaultLogger(argv[0], logPath);
22  g3::initializeLogging(g3log.get());
23  cout << "If you do not want log in /tmp, define environment "
24  << "variable G3LOG_log_dir e.g. with value ./ " << endl;
25  // cout << "If you want log on stderr, specify environment" << " variable
26  // GLOG_logtostderr with value
27  // true. "
28  // << endl;
29  cout << "Process the objdriver output with \"cut -f 2 -d ] <logfile>\" to "
30  "get a reasonable output."
31  << endl;
32 
33  // Command line description.
34  TCLAP::CmdLine cmd("Command description message", ' ', "0.9");
35  TCLAP::ValueArg<string> nameArg("n", "name", "Name to print", true, "homer", "string", cmd);
36  TCLAP::SwitchArg reverseSwitch("r", "reverse", "Print name backwards", cmd, false);
37 
38  // Parse command line and get the value each argument.
39  cmd.parse(argc, static_cast<const char* const*>(argv));
40  std::string name(const_cast<const std::string&>(nameArg.getValue()));
41  bool reverseName = reverseSwitch.getValue();
42 
43  // Do what you intend.
44  if (reverseName) {
45  reverse(name.begin(), name.end());
46  cout << "My name (spelled backwards) is: " << name << endl;
47  } else {
48  cout << "My name is: " << name << endl;
49  }
50 
51  // Straight logging to google log
52  LOG(INFO) << "hello there: " << endl;
53  } catch (TCLAP::ArgException& e) {
54  cerr << "error: " << e.error() << " for argument " << e.argId() << std::endl;
55  } catch (exception& e) {
56  cerr << e.what() << endl;
57  } catch (...) {
58  cerr << "Unknown exception" << endl;
59  }
60  cout << "Done, exiting ..." << endl;
61  return 0;
62 }
Comprehensive include file for all tracer classes.
int main(int argc, char *argv[])
Definition: logdemo.cpp:12