Commit a9d3b969 by amir

add colorful logging

parent 85220c52
......@@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 2.8.12)
project(Microservice)
# version stuff
set (Microservice_VERSION_MAJOR 1)
set (Microservice_VERSION_MINOR 3)
set (Microservice_VERSION_MINOR 4)
set (Microservice_VERSION_PATCH 0)
set(Microservice_VERSION_STRING ${Microservice_VERSION_MAJOR}.${Microservice_VERSION_MINOR}.${Microservice_VERSION_PATCH})
......
## C++ Microservice Framework
## VERSIONS:
# 1.4.0
- Add colorful logging
# 1.3.0
- Async Rest Client/Server using ZMQ
- Add gethrtime in CommonUtils to get timestamp (nanoseconds , not for datetime)
......
- memory leak on performance testing of SendZmqRestRequests
- upon receiving the response , forward it to a new task to be carried by another thread
- catch http exception when callback url is down
\ No newline at end of file
......@@ -21,10 +21,64 @@
#include <log4cpp/PatternLayout.hh>
thread_local char ba_LogBuffer[nsMicroservice_Constants::MAX_LOGEER_BUFF_LENGTH];
#define RST "\x1B[0m"
#define KRED "\x1B[31m"
#define KGRN "\x1B[32m"
#define KYEL "\x1B[33m"
#define KBLU "\x1B[34m"
#define KMAG "\x1B[35m"
#define KCYN "\x1B[36m"
#define KWHT "\x1B[37m"
#define FRED(x) KRED x RST
#define FGRN(x) KGRN x RST
#define FYEL(x) KYEL x RST
#define FBLU(x) KBLU x RST
#define FMAG(x) KMAG x RST
#define FCYN(x) KCYN x RST
#define FWHT(x) KWHT x RST
#define BOLD(x) "\x1B[1m" x RST
#define UNDL(x) "\x1B[4m" x RST
#define MAKE_MESSAGE {int len; va_list ap; va_start( ap , stringFormat );\
len = ( vsnprintf(ba_LogBuffer, nsMicroservice_Constants::MAX_LOGEER_BUFF_LENGTH, stringFormat, ap ) ); va_end(ap);}
/**
* class for output to console in colors....yeah
*/
class cMicroservices_ILoggerLog4cppImpl::ColorOstreamAppender : public log4cpp::OstreamAppender {
public:
ColorOstreamAppender(const std::string &name, std::ostream *stream) : OstreamAppender(name, stream) {}
protected:
void _append(const log4cpp::LoggingEvent &event) override {
switch (event.priority){
case log4cpp::Priority::ALERT:
case log4cpp::Priority::ERROR:
case log4cpp::Priority::CRIT:
case log4cpp::Priority::FATAL:
(*_stream) << KRED << _getLayout().format(event) << RST;
break;
case log4cpp::Priority::INFO:
(*_stream) << KBLU << _getLayout().format(event) << RST;
break;
case log4cpp::Priority::NOTICE:
(*_stream) << KGRN << _getLayout().format(event) << RST;
break;
case log4cpp::Priority::WARN:
(*_stream) << KYEL << _getLayout().format(event) << RST;
break;
case log4cpp::Priority::DEBUG:
(*_stream) << KWHT << _getLayout().format(event) << RST;
break;
}
}
};
/**
*
* @param name
......@@ -37,7 +91,7 @@ void cMicroservices_ILoggerLog4cppImpl::initDefaultLogger(const char* name){
char* logToConsole = getenv("log4cpp.console");
if(logToConsole)
{
consuleAappender = new log4cpp::OstreamAppender("console", &std::cout);
consuleAappender = new ColorOstreamAppender("console", &std::cout);//log4cpp::OstreamAppender("console", &std::cout);
log4cpp::PatternLayout *consoleLayout = new log4cpp::PatternLayout();
consoleLayout->setConversionPattern(layoutPattern);
consuleAappender->setLayout(consoleLayout);
......
......@@ -20,6 +20,9 @@
class cMicroservices_ILoggerLog4cppImpl: public nsMicroservice_Iface::ILogger
{
public:
class ColorOstreamAppender;
private:
log4cpp::Category* mpc_Logger;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment