WIP: main
This commit is contained in:
parent
f25f34565a
commit
15730b470e
52 changed files with 2438 additions and 208 deletions
53
service/server/log.cpp
Normal file
53
service/server/log.cpp
Normal file
|
@ -0,0 +1,53 @@
|
|||
#include <QDir>
|
||||
#include <QStandardPaths>
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include "log.h"
|
||||
#include "defines.h"
|
||||
#include "utils.h"
|
||||
|
||||
QFile Log::m_file;
|
||||
QTextStream Log::m_textStream;
|
||||
QString Log::m_logFileName;
|
||||
|
||||
void debugMessageHandler(QtMsgType type, const QMessageLogContext& context, const QString& msg)
|
||||
{
|
||||
if (msg.simplified().isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Log::m_textStream << qFormatLogMessage(type, context, msg) << endl << flush;
|
||||
|
||||
std::cout << qFormatLogMessage(type, context, msg).toStdString() << std::endl << std::flush;
|
||||
}
|
||||
|
||||
bool Log::initialize()
|
||||
{
|
||||
QString path = Utils::systemLogPath();
|
||||
QDir appDir(path);
|
||||
if (!appDir.mkpath(path)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
m_logFileName = QString("%1.log").arg(SERVICE_NAME);
|
||||
|
||||
qSetMessagePattern("%{time yyyy-MM-dd hh:mm:ss} %{type} %{message}");
|
||||
|
||||
m_file.setFileName(appDir.filePath(m_logFileName));
|
||||
if (!m_file.open(QIODevice::WriteOnly | QIODevice::Truncate)) {
|
||||
qWarning() << "Cannot open log file:" << m_logFileName;
|
||||
return false;
|
||||
}
|
||||
m_file.setTextModeEnabled(true);
|
||||
m_textStream.setDevice(&m_file);
|
||||
qInstallMessageHandler(debugMessageHandler);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
QString Log::serviceLogFileNamePath()
|
||||
{
|
||||
return m_file.fileName();
|
||||
}
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue