mirror of
https://github.com/tnodir/fort
synced 2024-11-15 05:46:03 +00:00
UI: Logger: Refactor updating.
This commit is contained in:
parent
d6275f4f6f
commit
da78f3e49d
@ -436,9 +436,11 @@ void FortManager::restoreWindowState()
|
||||
|
||||
void FortManager::updateLogger()
|
||||
{
|
||||
Logger::setupLogging(m_firewallConf->logErrors(),
|
||||
m_fortSettings->debug(),
|
||||
m_fortSettings->console());
|
||||
Logger *logger = Logger::instance();
|
||||
|
||||
logger->setActive(m_firewallConf->logErrors());
|
||||
logger->setDebug(m_fortSettings->debug());
|
||||
logger->setConsole(m_fortSettings->console());
|
||||
}
|
||||
|
||||
void FortManager::updateTrayMenu()
|
||||
|
@ -17,6 +17,7 @@ static QtMessageHandler g_oldMessageHandler = nullptr;
|
||||
Logger::Logger(QObject *parent) :
|
||||
QObject(parent),
|
||||
m_active(false),
|
||||
m_debug(false),
|
||||
m_console(false),
|
||||
m_writing(false)
|
||||
{
|
||||
@ -33,6 +34,35 @@ Logger *Logger::instance()
|
||||
return g_instanceLogger;
|
||||
}
|
||||
|
||||
void Logger::setActive(bool active)
|
||||
{
|
||||
if (m_active != active) {
|
||||
m_active = active;
|
||||
}
|
||||
}
|
||||
|
||||
void Logger::setDebug(bool debug)
|
||||
{
|
||||
if (m_debug != debug) {
|
||||
m_debug = debug;
|
||||
|
||||
QLoggingCategory::setFilterRules(debug ? QString() : "*.debug=false");
|
||||
}
|
||||
}
|
||||
|
||||
void Logger::setConsole(bool console)
|
||||
{
|
||||
if (m_console != console) {
|
||||
m_console = console;
|
||||
|
||||
if (console) {
|
||||
AllocConsole();
|
||||
} else {
|
||||
FreeConsole();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Logger::setPath(const QString &path)
|
||||
{
|
||||
m_dir.setPath(path);
|
||||
@ -174,17 +204,3 @@ void Logger::messageHandler(QtMsgType type,
|
||||
g_oldMessageHandler(type, context, message);
|
||||
}
|
||||
}
|
||||
|
||||
void Logger::setupLogging(bool enabled, bool debug, bool console)
|
||||
{
|
||||
QLoggingCategory::setFilterRules(debug ? QString() : "*.debug=false");
|
||||
|
||||
instance()->setActive(enabled);
|
||||
instance()->setConsole(console);
|
||||
|
||||
if (console) {
|
||||
AllocConsole();
|
||||
} else {
|
||||
FreeConsole();
|
||||
}
|
||||
}
|
||||
|
@ -17,17 +17,18 @@ public:
|
||||
Q_ENUM(LogLevel)
|
||||
|
||||
bool active() const { return m_active; }
|
||||
void setActive(bool active) { m_active = active; }
|
||||
void setActive(bool active);
|
||||
|
||||
bool debug() const { return m_debug; }
|
||||
void setDebug(bool debug);
|
||||
|
||||
bool console() const { return m_console; }
|
||||
void setConsole(bool console) { m_console = console; }
|
||||
void setConsole(bool console);
|
||||
|
||||
void setPath(const QString &path);
|
||||
|
||||
static Logger *instance();
|
||||
|
||||
static void setupLogging(bool enabled, bool debug, bool console);
|
||||
|
||||
public slots:
|
||||
void writeLog(const QString &message, LogLevel level = Info);
|
||||
void writeLogList(const QString &message, const QStringList &list,
|
||||
@ -50,6 +51,7 @@ private:
|
||||
|
||||
private:
|
||||
uint m_active : 1;
|
||||
uint m_debug : 1;
|
||||
uint m_console : 1;
|
||||
uint m_writing : 1;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user