• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Stellarium / stellarium / 13369985667

17 Feb 2025 12:13PM UTC coverage: 12.083% (+0.006%) from 12.077%
13369985667

Pull #4139

github

10110111
Move printing of system info out of StelLogger
Pull Request #4139: Move printing of system info out of StelLogger

14617 of 120976 relevant lines covered (12.08%)

18910.51 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/StelLogger.cpp
1
/*
2
 * Stellarium
3
 * Copyright (C) 2009 Fabien Chereau
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA  02110-1335, USA.
18
 */
19

20
#include "StelLogger.hpp"
21

22
// Init statics variables.
23
QFile StelLogger::logFile;
24
QString StelLogger::log;
25
QMutex StelLogger::fileMutex;
26

27
void StelLogger::init(const QString& logFilePath)
×
28
{
29
        logFile.setFileName(logFilePath);
×
30

31
        if (logFile.open(QIODevice::WriteOnly | QIODevice::Truncate | QIODevice::Text | QIODevice::Unbuffered))
×
32
                qInstallMessageHandler(StelLogger::debugLogHandler);
×
33
}
×
34

35
void StelLogger::deinit()
×
36
{
37
        qInstallMessageHandler(Q_NULLPTR);
×
38
        logFile.close();
×
39
}
×
40

41
void StelLogger::debugLogHandler(QtMsgType type, const QMessageLogContext& ctx, const QString& msg)
×
42
{
43
        // *** NOTE: see original Qt source in qlogging.cpp (qDefaultMessageHandler) for sensible default code
44

45
        //use Qt to format the log message, if possible
46
        //this uses the format set by qSetMessagePattern
47
        //or QT_MESSAGE_PATTERN environment var
48
        QString fmt = qFormatLogMessage(type,ctx,msg);
×
49
        //do nothing for null messages
50
        if(fmt.isNull())
×
51
                return;
×
52

53
        //always append newline
54
        fmt.append(QLatin1Char('\n'));
×
55

56
#ifdef Q_OS_WIN
57
        //Send debug messages to Debugger, if one is attached, instead of stderr
58
        //This seems to avoid output delays in Qt Creator, allowing for easier debugging
59
        //Seems to work fine with MSVC and MinGW
60
        if (IsDebuggerPresent())
61
        {
62
                OutputDebugStringW(reinterpret_cast<const wchar_t *>(fmt.utf16()));
63
        }
64
        else
65
#endif
66
        {
67
                //this does the same as the default handler in qlogging.cpp
68
                fprintf(stderr, "%s", qPrintable(fmt));
×
69
                fflush(stderr);
×
70
        }
71
        writeLog(fmt);
×
72
}
×
73

74
void StelLogger::writeLog(QString msg)
×
75
{
76
        if (!msg.endsWith('\n'))
×
77
                msg.append(QLatin1Char('\n'));
×
78

79
        fileMutex.lock();
×
80
        const auto utf8 = msg.toUtf8();
×
81
        logFile.write(utf8.constData(), utf8.size());
×
82
        log += msg;
×
83
        fileMutex.unlock();
×
84
}
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc