Last active
June 24, 2017 16:40
-
-
Save marceljanerfont/8fefd80ea65753a8c05fc447fc98744f to your computer and use it in GitHub Desktop.
It will print to console output with a us timestamp and a gtest friendly format in green colour. E.g. LOG_INFO << "result: " << result;
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <iomanip> | |
#include <chrono> | |
#define Color_Off "\033[0m" | |
#define Black "\033[1;30m" | |
#define Red "\033[1;31m" | |
#define Green "\033[1;32m" | |
#define Yellow "\033[1;33m" | |
#define Blue "\033[1;34m" | |
#define Purple "\033[1;35m" | |
#define Cyan "\033[1;36m" | |
#define White "\033[1;37m" | |
// For print green messages in google test output | |
class GTestLoggerCout : public std::stringstream { | |
public: | |
GTestLoggerCout(const std::string &colour): m_colour(colour) {} | |
~GTestLoggerCout() { | |
static auto start = std::chrono::high_resolution_clock::now(); | |
auto end = std::chrono::high_resolution_clock::now(); | |
std::cout << m_colour << "[ ] " << | |
"[" << std::setfill('0') << std::setw(6) << | |
std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count() << " ms] " << | |
str() << Color_Off << std::endl; | |
} | |
std::string m_colour; | |
}; | |
#define LOG_INFO GTestLoggerCout(Green) | |
#define LOG_WARN GTestLoggerCout(Purple) | |
#define LOG_ERROR GTestLoggerCout(Red) | |
////////////////////// |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment