renamed log class in service project to logger
This commit is contained in:
parent
3b2948d4dd
commit
686fc754b2
7 changed files with 29 additions and 28 deletions
|
|
@ -83,7 +83,7 @@ bool Logger::init()
|
||||||
|
|
||||||
void Logger::deInit()
|
void Logger::deInit()
|
||||||
{
|
{
|
||||||
qInstallMessageHandler(0);
|
qInstallMessageHandler(nullptr);
|
||||||
qSetMessagePattern("%{message}");
|
qSetMessagePattern("%{message}");
|
||||||
m_textStream.setDevice(nullptr);
|
m_textStream.setDevice(nullptr);
|
||||||
m_file.close();
|
m_file.close();
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@
|
||||||
#include <QLocalSocket>
|
#include <QLocalSocket>
|
||||||
|
|
||||||
#include "router.h"
|
#include "router.h"
|
||||||
#include "log.h"
|
#include "logger.h"
|
||||||
|
|
||||||
#ifdef Q_OS_WIN
|
#ifdef Q_OS_WIN
|
||||||
#include "tapcontroller_win.h"
|
#include "tapcontroller_win.h"
|
||||||
|
|
@ -111,16 +111,16 @@ QStringList IpcServer::getTapList()
|
||||||
void IpcServer::cleanUp()
|
void IpcServer::cleanUp()
|
||||||
{
|
{
|
||||||
qDebug() << "IpcServer::cleanUp";
|
qDebug() << "IpcServer::cleanUp";
|
||||||
Log::deinit();
|
Logger::deinit();
|
||||||
Log::cleanUp();
|
Logger::cleanUp();
|
||||||
}
|
}
|
||||||
|
|
||||||
void IpcServer::setLogsEnabled(bool enabled)
|
void IpcServer::setLogsEnabled(bool enabled)
|
||||||
{
|
{
|
||||||
if (enabled) {
|
if (enabled) {
|
||||||
Log::init();
|
Logger::init();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Log::deinit();
|
Logger::deinit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@ set(HEADERS
|
||||||
${CMAKE_CURRENT_LIST_DIR}/../../ipc/ipcserver.h
|
${CMAKE_CURRENT_LIST_DIR}/../../ipc/ipcserver.h
|
||||||
${CMAKE_CURRENT_LIST_DIR}/../../ipc/ipcserverprocess.h
|
${CMAKE_CURRENT_LIST_DIR}/../../ipc/ipcserverprocess.h
|
||||||
${CMAKE_CURRENT_LIST_DIR}/localserver.h
|
${CMAKE_CURRENT_LIST_DIR}/localserver.h
|
||||||
${CMAKE_CURRENT_LIST_DIR}/log.h
|
${CMAKE_CURRENT_LIST_DIR}/logger.h
|
||||||
${CMAKE_CURRENT_LIST_DIR}/router.h
|
${CMAKE_CURRENT_LIST_DIR}/router.h
|
||||||
${CMAKE_CURRENT_LIST_DIR}/systemservice.h
|
${CMAKE_CURRENT_LIST_DIR}/systemservice.h
|
||||||
)
|
)
|
||||||
|
|
@ -25,7 +25,7 @@ set(SOURCES
|
||||||
${CMAKE_CURRENT_LIST_DIR}/../../ipc/ipcserver.cpp
|
${CMAKE_CURRENT_LIST_DIR}/../../ipc/ipcserver.cpp
|
||||||
${CMAKE_CURRENT_LIST_DIR}/../../ipc/ipcserverprocess.cpp
|
${CMAKE_CURRENT_LIST_DIR}/../../ipc/ipcserverprocess.cpp
|
||||||
${CMAKE_CURRENT_LIST_DIR}/localserver.cpp
|
${CMAKE_CURRENT_LIST_DIR}/localserver.cpp
|
||||||
${CMAKE_CURRENT_LIST_DIR}/log.cpp
|
${CMAKE_CURRENT_LIST_DIR}/logger.cpp
|
||||||
${CMAKE_CURRENT_LIST_DIR}/main.cpp
|
${CMAKE_CURRENT_LIST_DIR}/main.cpp
|
||||||
${CMAKE_CURRENT_LIST_DIR}/router.cpp
|
${CMAKE_CURRENT_LIST_DIR}/router.cpp
|
||||||
${CMAKE_CURRENT_LIST_DIR}/systemservice.cpp
|
${CMAKE_CURRENT_LIST_DIR}/systemservice.cpp
|
||||||
|
|
@ -82,9 +82,9 @@ endif()
|
||||||
include(${CMAKE_CURRENT_LIST_DIR}/../src/qtservice.cmake)
|
include(${CMAKE_CURRENT_LIST_DIR}/../src/qtservice.cmake)
|
||||||
|
|
||||||
include_directories(
|
include_directories(
|
||||||
|
${CMAKE_CURRENT_LIST_DIR}
|
||||||
${CMAKE_CURRENT_LIST_DIR}/../../client
|
${CMAKE_CURRENT_LIST_DIR}/../../client
|
||||||
${CMAKE_CURRENT_LIST_DIR}/../../ipc
|
${CMAKE_CURRENT_LIST_DIR}/../../ipc
|
||||||
${CMAKE_CURRENT_LIST_DIR}
|
|
||||||
${CMAKE_CURRENT_BINARY_DIR}
|
${CMAKE_CURRENT_BINARY_DIR}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -107,4 +107,4 @@ add_custom_command(
|
||||||
${CMAKE_SOURCE_DIR}/deploy/data/${DEPLOY_ARTIFACT_PATH}
|
${CMAKE_SOURCE_DIR}/deploy/data/${DEPLOY_ARTIFACT_PATH}
|
||||||
$<TARGET_FILE_DIR:${PROJECT}>
|
$<TARGET_FILE_DIR:${PROJECT}>
|
||||||
COMMAND_EXPAND_LISTS
|
COMMAND_EXPAND_LISTS
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -1,15 +1,16 @@
|
||||||
|
#include "logger.h"
|
||||||
|
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
#include <QStandardPaths>
|
#include <QStandardPaths>
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
#include "log.h"
|
|
||||||
#include "defines.h"
|
#include "defines.h"
|
||||||
#include "utilities.h"
|
#include "utilities.h"
|
||||||
|
|
||||||
QFile Log::m_file;
|
QFile Logger::m_file;
|
||||||
QTextStream Log::m_textStream;
|
QTextStream Logger::m_textStream;
|
||||||
QString Log::m_logFileName = QString("%1.log").arg(SERVICE_NAME);
|
QString Logger::m_logFileName = QString("%1.log").arg(SERVICE_NAME);
|
||||||
|
|
||||||
void debugMessageHandler(QtMsgType type, const QMessageLogContext& context, const QString& msg)
|
void debugMessageHandler(QtMsgType type, const QMessageLogContext& context, const QString& msg)
|
||||||
{
|
{
|
||||||
|
|
@ -17,12 +18,12 @@ void debugMessageHandler(QtMsgType type, const QMessageLogContext& context, cons
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Log::m_textStream << qFormatLogMessage(type, context, msg) << Qt::endl << Qt::flush;
|
Logger::m_textStream << qFormatLogMessage(type, context, msg) << Qt::endl << Qt::flush;
|
||||||
|
|
||||||
std::cout << qFormatLogMessage(type, context, msg).toStdString() << std::endl << std::flush;
|
std::cout << qFormatLogMessage(type, context, msg).toStdString() << std::endl << std::flush;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Log::init()
|
bool Logger::init()
|
||||||
{
|
{
|
||||||
if (m_file.isOpen()) return true;
|
if (m_file.isOpen()) return true;
|
||||||
|
|
||||||
|
|
@ -46,19 +47,19 @@ bool Log::init()
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Log::deinit()
|
void Logger::deinit()
|
||||||
{
|
{
|
||||||
m_file.close();
|
m_file.close();
|
||||||
m_textStream.setDevice(nullptr);
|
m_textStream.setDevice(nullptr);
|
||||||
qInstallMessageHandler(nullptr);
|
qInstallMessageHandler(nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
QString Log::serviceLogFileNamePath()
|
QString Logger::serviceLogFileNamePath()
|
||||||
{
|
{
|
||||||
return m_file.fileName();
|
return m_file.fileName();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Log::clearLogs()
|
void Logger::clearLogs()
|
||||||
{
|
{
|
||||||
bool isLogActive = m_file.isOpen();
|
bool isLogActive = m_file.isOpen();
|
||||||
m_file.close();
|
m_file.close();
|
||||||
|
|
@ -78,7 +79,7 @@ void Log::clearLogs()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Log::cleanUp()
|
void Logger::cleanUp()
|
||||||
{
|
{
|
||||||
clearLogs();
|
clearLogs();
|
||||||
deinit();
|
deinit();
|
||||||
|
|
@ -1,12 +1,12 @@
|
||||||
#ifndef LOG_H
|
#ifndef LOGGER_H
|
||||||
#define LOG_H
|
#define LOGGER_H
|
||||||
|
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
#include <QTextStream>
|
#include <QTextStream>
|
||||||
|
|
||||||
class Log
|
class Logger
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static bool init();
|
static bool init();
|
||||||
|
|
@ -25,4 +25,4 @@ private:
|
||||||
static QTextStream m_textStream;
|
static QTextStream m_textStream;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // LOG_H
|
#endif // LOGGER_H
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
#include "defines.h"
|
#include "defines.h"
|
||||||
#include "localserver.h"
|
#include "localserver.h"
|
||||||
#include "log.h"
|
#include "logger.h"
|
||||||
#include "systemservice.h"
|
#include "systemservice.h"
|
||||||
#include "utilities.h"
|
#include "utilities.h"
|
||||||
|
|
||||||
|
|
@ -20,7 +20,7 @@ int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
Utils::initializePath(Utils::systemLogPath());
|
Utils::initializePath(Utils::systemLogPath());
|
||||||
|
|
||||||
Log::init();
|
Logger::init();
|
||||||
|
|
||||||
if (argc == 2) {
|
if (argc == 2) {
|
||||||
qInfo() << "Started as console application";
|
qInfo() << "Started as console application";
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ HEADERS = \
|
||||||
../../ipc/ipcserver.h \
|
../../ipc/ipcserver.h \
|
||||||
../../ipc/ipcserverprocess.h \
|
../../ipc/ipcserverprocess.h \
|
||||||
localserver.h \
|
localserver.h \
|
||||||
log.h \
|
logger.h \
|
||||||
router.h \
|
router.h \
|
||||||
systemservice.h
|
systemservice.h
|
||||||
|
|
||||||
|
|
@ -19,7 +19,7 @@ SOURCES = \
|
||||||
../../ipc/ipcserver.cpp \
|
../../ipc/ipcserver.cpp \
|
||||||
../../ipc/ipcserverprocess.cpp \
|
../../ipc/ipcserverprocess.cpp \
|
||||||
localserver.cpp \
|
localserver.cpp \
|
||||||
log.cpp \
|
logger.cpp \
|
||||||
main.cpp \
|
main.cpp \
|
||||||
router.cpp \
|
router.cpp \
|
||||||
systemservice.cpp
|
systemservice.cpp
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue