Line data Source code
1 : #ifndef A0673BA5_EB6B_4B00_810D_2B7FE0295361_HPP 2 : #define A0673BA5_EB6B_4B00_810D_2B7FE0295361_HPP 3 : 4 : /** 5 : * Here we configure logging and expose the initLogging function that can also be called from the test executable 6 : */ 7 : 8 : #include <gflags/gflags.h> 9 : #include <glog/logging.h> 10 : 11 : #include <iomanip> 12 : #include <ostream> 13 : 14 : namespace cell 15 : { 16 : 17 : /** 18 : * @brief Formats the message in the format TIME - source:line LEVEL <message> 19 : */ 20 0 : void MyPrefixFormatter(std::ostream& s, const google::LogMessage& m, void* /*data*/) 21 : { 22 : using std::setw, std::setfill; 23 0 : s << setw(2) << m.time().hour() << ':' << setw(2) << m.time().min() << ':' << setw(2) << m.time().sec() << "," 24 0 : << setw(3) << m.time().usec() / 1000 << " - " << m.basename() << ':' << m.line() << " " << setfill(' ') << setw(7) 25 0 : << google::GetLogSeverityName(m.severity()); 26 0 : } 27 : 28 : /** 29 : * @brief Installs the above PrefixFormatter, lets gflags parse command line options (like --v=N) and configures the 30 : * logging 31 : */ 32 1 : void initLogging(int argc, char** argv) 33 : { 34 : // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) 35 1 : google::InitGoogleLogging(argv[0]); 36 1 : gflags::ParseCommandLineFlags(&argc, &argv, true); 37 : 38 1 : FLAGS_alsologtostderr = true; // Log both to file and stderr 39 1 : FLAGS_logbuflevel = -1; // No buffering, write immediately 40 1 : FLAGS_minloglevel = 0; // Don't suppress any log messages in general 41 1 : FLAGS_stderrthreshold = 0; // Don't suppress any log messages for stderr output 42 1 : FLAGS_timestamp_in_logfile_name = false; // We just want a single logfile at the moment 43 1 : FLAGS_colorlogtostderr = true; // Looks pretty, why not 44 : 45 1 : google::InstallPrefixFormatter(&MyPrefixFormatter); 46 1 : } 47 : 48 : } // namespace cell 49 : 50 : #endif /* A0673BA5_EB6B_4B00_810D_2B7FE0295361_HPP */