I created a global definition with additional information:
#include <iostream> #include <ctime> #include <iomanip> #define INFO std::cout << std::put_time(std::localtime(&time_now), "%y-%m-%d %OH:%OM:%OS") << " [INFO] " << __FILE__ << "(" << __FUNCTION__ << ":" << __LINE__ << ") >> " #define ERROR std::cout << std::put_time(std::localtime(&time_now), "%y-%m-%d %OH:%OM:%OS") << " [ERROR] " << __FILE__ << "(" << __FUNCTION__ << ":" << __LINE__ << ") >> " static std::time_t time_now = std::time(nullptr);
Use it as follows:
INFO << "Hello world" << std::endl; ERROR << "Goodbye world" << std::endl;
Output Example:
16-06-23 21:33:19 [INFO] src/main.cpp(main:6) >> Hello world 16-06-23 21:33:19 [ERROR] src/main.cpp(main:7) >> Goodbye world
Put these lines in the header file. I find this very useful for debugging etc.
xinthose Jun 24 '16 at 2:37 2016-06-24 02:37
source share