MNE-CPP 0.1.9
A Framework for Electrophysiology
Loading...
Searching...
No Matches
applicationlogger.cpp
1//=============================================================================================================
36//=============================================================================================================
37// INCLUDES
38//=============================================================================================================
39
40#include <iostream>
41#include "applicationlogger.h"
42#include <stdio.h>
43
44//=============================================================================================================
45// QT INCLUDES
46//=============================================================================================================
47
48#include <QtGlobal>
49#include <QDebug>
50#include <QTime>
51#include <QMutexLocker>
52
53//=============================================================================================================
54// USED NAMESPACES
55//=============================================================================================================
56
57using namespace UTILSLIB;
58//using namespace std;
59
60//=============================================================================================================
61// Definitions
62//=============================================================================================================
63
64#ifdef WIN32
65 #include <wchar.h>
66 #include <windows.h>
67 #define COLOR_INFO SetConsoleTextAttribute(hOut, 0x02) //green
68 #define COLOR_DEBUG SetConsoleTextAttribute(hOut, 0x02) //green
69 #define COLOR_WARN SetConsoleTextAttribute(hOut, 0x0E) //yellow
70 #define COLOR_FATAL SetConsoleTextAttribute(hOut, 0x0E) //yellow
71 #define COLOR_CRITICAL SetConsoleTextAttribute(hOut, 0x04) //red
72 #define COLOR_RESET SetConsoleTextAttribute(hOut, 7) //reset
73 #define LOG_WRITE(OUTPUT, COLOR, LEVEL, MSG) COLOR; OUTPUT << LEVEL;COLOR_RESET; OUTPUT<< MSG << std::endl
74
75#else
76 #define COLOR_INFO "\033[32;1m" //green
77 #define COLOR_DEBUG "\033[32;1m" //green
78 #define COLOR_WARN "\033[33;1m" //yellow
79 #define COLOR_CRITICAL "\033[31;1m" //red
80 #define COLOR_FATAL "\033[33;1m" //yellow
81 #define COLOR_RESET "\033[0m" //reset
82
83 #define LOG_WRITE(OUTPUT, COLOR, LEVEL, MSG) OUTPUT << COLOR << LEVEL << COLOR_RESET << MSG << "\n"
84#endif
85
86std::mutex ApplicationLogger::m_mutex;
87
88//=============================================================================================================
89// DEFINE MEMBER METHODS
90//=============================================================================================================
91
93 const QMessageLogContext &context,
94 const QString &msg)
95{
96 Q_UNUSED(context)
97
98 QString sDate = QString("] ");
99 // Comment in following line if you want to display the date and time of the message
100 //sDate = QString(" %1] ").arg(QDateTime::currentDateTime().toString("dd/MM/yyyy hh:mm:ss.z"));
101
102 #ifdef WIN32
103 // Enable colored output for
104 // Set output mode to handle virtual terminal sequences
105 HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
106 #endif
107
108 m_mutex.lock();
109 switch (type) {
110 case QtWarningMsg:
111 LOG_WRITE(std::cout, COLOR_WARN, QString("[WARN%1").arg(sDate).toStdString(), msg.toStdString());
112 break;
113 case QtCriticalMsg:
114 LOG_WRITE(std::cout, COLOR_CRITICAL, QString("[CRIT%1").arg(sDate).toStdString(), msg.toStdString());
115 break;
116 case QtFatalMsg:
117 LOG_WRITE(std::cout, COLOR_FATAL, QString("[FATAL%1").arg(sDate).toStdString(), msg.toStdString());
118 break;
119 case QtDebugMsg:
120 LOG_WRITE(std::cout, COLOR_DEBUG, QString("[DEBUG%1").arg(sDate).toStdString(), msg.toStdString());
121 break;
122 case QtInfoMsg:
123 LOG_WRITE(std::cout, COLOR_INFO, QString("[INFO%1").arg(sDate).toStdString(), msg.toStdString());
124 break;
125 default:
126 LOG_WRITE(std::cout, COLOR_RESET, "", msg.toStdString());
127 break;
128 }
129 m_mutex.unlock();
130}
Contains the declaration of the ApplicationLogger class.
static void customLogWriter(QtMsgType type, const QMessageLogContext &context, const QString &msg)