MCPcopy Create free account
hub / github.com/cpvrlab/ImagePlay / logMessage

Method logMessage

ImagePlay/src/MainWindow.cpp:130–196  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

128}
129
130void MainWindow::logMessage(QtMsgType type, const QMessageLogContext &context, const QString &msg)
131{
132 QString line;
133 int _debugLevel = 1;
134 QString timestamp = QTime::currentTime().toString("hh:mm:ss");
135 switch (type) {
136 case QtDebugMsg:
137 line = QString("%1 Debug: %2").arg(timestamp).arg(msg);
138 if (ui->dockLog->isVisible() && _debugLevel >= 1)
139 ui->txtLog->append(QString("<b>%1</b> %2").arg(timestamp).arg(msg));
140 break;
141 case QtWarningMsg:
142 line = QString("%1 Warning: %2").arg(timestamp).arg(msg);
143 if (ui->dockLog->isVisible())
144 ui->txtLog->append(QString("<b style=\"color:blue\">%1</b> %2").arg(timestamp).arg(msg));
145 break;
146 case QtCriticalMsg:
147 line = QString("%1 Critical: %2").arg(timestamp).arg(msg);
148 if (ui->dockLog->isVisible())
149 ui->txtLog->append(QString("<b style=\"color:red\">%1</b> %2").arg(timestamp).arg(msg));
150 break;
151 case QtFatalMsg:
152 line = QString("%1 Fatal: %2").arg(timestamp).arg(msg);
153 if (ui->dockLog->isVisible())
154 ui->txtLog->append(QString("<b style=\"color:red\">%1 Fatal:</b> %2").arg(timestamp).arg(msg));
155 abort();
156 }
157
158
159 // write log file. one file per day
160 if(logFileEnabled())
161 {
162#ifdef Q_OS_WIN
163 QDir logDir(qApp->applicationDirPath() + "/log/");
164 if(!logDir.exists())
165 {
166 logDir.mkdir(".");
167 }
168
169 QString fileName = logDir.absolutePath();
170 fileName += "/";
171 fileName += QDate::currentDate().toString("yyyy-MM-dd");
172 fileName += ".log";
173#else
174 QDir logDir("/tmp/");
175
176
177 QString fileName = logDir.absolutePath();
178 fileName += "/ImagePlay.";
179 fileName += QDate::currentDate().toString("yyyy-MM-dd");
180 fileName += ".log";
181#endif
182
183 QFile logFile(fileName);
184
185 if (!logFile.open(QIODevice::Append | QIODevice::Text))
186 {
187 ui->txtLog->append(logFile.fileName() + QString(" not writable!"));

Callers 1

customMessageOutputFunction · 0.80

Calls 1

toStringMethod · 0.45

Tested by

no test coverage detected