QGIS API Documentation 3.99.0-Master (7d2ca374f2d)
Loading...
Searching...
No Matches
qgsmessagelog.h
Go to the documentation of this file.
1/***************************************************************************
2 qgsmessagelog.h - interface for logging messages
3 ----------------------
4 begin : October 2011
5 copyright : (C) 2011 by Juergen E. Fischer
6 email : jef at norbit dot de
7 ***************************************************************************
8 * *
9 * This program is free software; you can redistribute it and/or modify *
10 * it under the terms of the GNU General Public License as published by *
11 * the Free Software Foundation; either version 2 of the License, or *
12 * (at your option) any later version. *
13 * *
14 ***************************************************************************/
15
16#ifndef QGSMESSAGELOG_H
17#define QGSMESSAGELOG_H
18
19#include "qgis.h"
20#include "qgis_core.h"
21
22#include <QObject>
23#include <QString>
24
39class CORE_EXPORT QgsMessageLog : public QObject
40{
41 Q_OBJECT
42
43 public:
44
45 QgsMessageLog() = default;
46
47 // TODO: Update this code to use std::source_location from C++20 when transitioning to a fully C++20-compliant codebase.
48 // Currently, we rely on __builtin_XXX functions (e.g., __builtin_FILE(), __builtin_LINE()),
49 // which have been successfully tested across multiple systems (Windows, macOS, Linux, FreeBSD)
50 // and compilers (LLVM, GCC, MSVC).
51 // Note: We tested with LLVM on FreeBSD and macOS, and std::experimental::source_location is not available.
52 // It works fine with GNU. It also seems unavailable with MSVC.
53 // For now, we stick with __builtin_XXX because it is "portable" and functional across all tested environments.
54 // We'll switch to std::source_location once the transition to C++20 is complete.
55
65 static void logMessage( const QString &message, const QString &tag = QString(), Qgis::MessageLevel level = Qgis::MessageLevel::Warning, bool notifyUser = true,
66 const char *file = __builtin_FILE(), const char *function = __builtin_FUNCTION(), int line = __builtin_LINE(), Qgis::StringFormat format = Qgis::StringFormat::PlainText );
67
68 signals:
69
78 Q_DECL_DEPRECATED void messageReceived( const QString &message, const QString &tag, Qgis::MessageLevel level ) SIP_DEPRECATED;
79
86 void messageReceivedWithFormat( const QString &message, const QString &tag, Qgis::MessageLevel level, Qgis::StringFormat );
87
88 //TODO QGIS 5.0 - remove received argument
89
98 void messageReceived( bool received );
99
100 private:
101
102 void emitMessage( const QString &message, const QString &tag, Qgis::MessageLevel level, bool notifyUser = true, Qgis::StringFormat format = Qgis::StringFormat::PlainText );
103
104 int mAdviseBlockCount = 0;
105
107
108};
109
124{
125 public:
126
133
136
138
139 private:
140
141#ifdef SIP_RUN
143#endif
144};
145
153class CORE_EXPORT QgsMessageLogConsole : public QObject
154{
155 Q_OBJECT
156
157 public:
158
163
164 protected:
165
174 QString formatLogMessage( const QString &message, const QString &tag, Qgis::MessageLevel level = Qgis::MessageLevel::Info ) const;
175
176 public slots:
177
185 virtual void logMessage( const QString &message, const QString &tag, Qgis::MessageLevel level );
186
197 virtual void logMessage( const QString &message, const QString &tag, Qgis::MessageLevel level, Qgis::StringFormat format );
198};
199
200#endif
MessageLevel
Level for messages This will be used both for message log and message bar in application.
Definition qgis.h:158
@ Warning
Warning message.
Definition qgis.h:160
@ Info
Information message.
Definition qgis.h:159
StringFormat
Format of log message.
Definition qgis.h:173
@ PlainText
Text message.
Definition qgis.h:174
QString formatLogMessage(const QString &message, const QString &tag, Qgis::MessageLevel level=Qgis::MessageLevel::Info) const
Formats a log message.
QgsMessageLogConsole()
Constructor for QgsMessageLogConsole.
virtual void logMessage(const QString &message, const QString &tag, Qgis::MessageLevel level)
Logs a message to stderr.
QgsMessageLogNotifyBlocker(const QgsMessageLogNotifyBlocker &other)=delete
QgsMessageLogNotifyBlocker & operator=(const QgsMessageLogNotifyBlocker &other)=delete
QgsMessageLogNotifyBlocker()
Constructor for QgsMessageLogNotifyBlocker.
void messageReceivedWithFormat(const QString &message, const QString &tag, Qgis::MessageLevel level, Qgis::StringFormat)
Emitted whenever the log receives a message.
static void logMessage(const QString &message, const QString &tag=QString(), Qgis::MessageLevel level=Qgis::MessageLevel::Warning, bool notifyUser=true, const char *file=__builtin_FILE(), const char *function=__builtin_FUNCTION(), int line=__builtin_LINE(), Qgis::StringFormat format=Qgis::StringFormat::PlainText)
Adds a message to the log instance (and creates it if necessary).
friend class QgsMessageLogNotifyBlocker
Q_DECL_DEPRECATED void messageReceived(const QString &message, const QString &tag, Qgis::MessageLevel level)
Emitted whenever the log receives a message.
void messageReceived(bool received)
Emitted whenever the log receives a message which is not a Qgis::MessageLevel::Info level message and...
QgsMessageLog()=default
#define SIP_DEPRECATED
Definition qgis_sip.h:113