refactor: Logger::instance return a pointer to the logger static object
This commit is contained in:
parent
78eae652fd
commit
c066e394a8
5 changed files with 6 additions and 8 deletions
|
|
@ -133,7 +133,7 @@ int main(int argc, char *argv[])
|
||||||
qInfo("%s v%s", kAppName, kDisplayVersion);
|
qInfo("%s v%s", kAppName, kDisplayVersion);
|
||||||
|
|
||||||
dotenv();
|
dotenv();
|
||||||
Logger::instance().loadEnvVars();
|
Logger::instance()->loadEnvVars();
|
||||||
|
|
||||||
#if defined(Q_OS_MAC)
|
#if defined(Q_OS_MAC)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -23,8 +23,6 @@ const auto kForceDebugMessages = QStringList{
|
||||||
"Unable to obtain clipboard."
|
"Unable to obtain clipboard."
|
||||||
};
|
};
|
||||||
|
|
||||||
Logger Logger::s_instance;
|
|
||||||
|
|
||||||
QString printLine(FILE *out, const QString &type, const QString &message, const QString &fileLine = "")
|
QString printLine(FILE *out, const QString &type, const QString &message, const QString &fileLine = "")
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -15,9 +15,10 @@ class Logger : public QObject
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static Logger &instance()
|
static Logger *instance()
|
||||||
{
|
{
|
||||||
return s_instance;
|
static Logger m;
|
||||||
|
return &m;
|
||||||
}
|
}
|
||||||
|
|
||||||
void loadEnvVars();
|
void loadEnvVars();
|
||||||
|
|
@ -27,7 +28,6 @@ Q_SIGNALS:
|
||||||
void newLine(const QString &line);
|
void newLine(const QString &line);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static Logger s_instance;
|
|
||||||
#ifdef NDEBUG
|
#ifdef NDEBUG
|
||||||
bool m_debug = false;
|
bool m_debug = false;
|
||||||
#else
|
#else
|
||||||
|
|
|
||||||
|
|
@ -90,7 +90,7 @@ QString fileLine(const QMessageLogContext &context)
|
||||||
void messageHandler(QtMsgType type, const QMessageLogContext &context, const QString &message)
|
void messageHandler(QtMsgType type, const QMessageLogContext &context, const QString &message)
|
||||||
{
|
{
|
||||||
const auto fileLine = messages::fileLine(context);
|
const auto fileLine = messages::fileLine(context);
|
||||||
Logger::instance().handleMessage(type, fileLine, message);
|
Logger::instance()->handleMessage(type, fileLine, message);
|
||||||
|
|
||||||
if (type == QtFatalMsg || type == QtCriticalMsg) {
|
if (type == QtFatalMsg || type == QtCriticalMsg) {
|
||||||
showErrorDialog(message, fileLine, type);
|
showErrorDialog(message, fileLine, type);
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,7 @@ LogWidget::LogWidget(QWidget *parent) : QWidget{parent}, m_textLog{new QPlainTex
|
||||||
setLayout(layout);
|
setLayout(layout);
|
||||||
|
|
||||||
connect(
|
connect(
|
||||||
&deskflow::gui::Logger::instance(), &deskflow::gui::Logger::newLine, m_textLog, &QPlainTextEdit::appendPlainText
|
deskflow::gui::Logger::instance(), &deskflow::gui::Logger::newLine, m_textLog, &QPlainTextEdit::appendPlainText
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue