QGIS API Documentation  2.99.0-Master (cd0ba91)
qgsmessagelog.cpp
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 #include "qgsmessagelog.h"
17 #include "qgsapplication.h"
18 #include "qgslogger.h"
19 #include <QDateTime>
20 #include <QMetaType>
21 #include <iostream>
22 
24 
25 void QgsMessageLog::logMessage( const QString &message, const QString &tag, QgsMessageLog::MessageLevel level )
26 {
27  QgsDebugMsg( QString( "%1 %2[%3] %4" ).arg( QDateTime::currentDateTime().toString( Qt::ISODate ), tag ).arg( level ).arg( message ) );
28 
29  QgsApplication::messageLog()->emitMessage( message, tag, level );
30 }
31 
32 void QgsMessageLog::emitMessage( const QString &message, const QString &tag, QgsMessageLog::MessageLevel level )
33 {
34  emit messageReceived( message, tag, level );
35  if ( level != QgsMessageLog::INFO )
36  {
37  emit messageReceived( true );
38  }
39 }
40 
42  : QObject( QgsApplication::messageLog() )
43 {
44  connect( QgsApplication::messageLog(), static_cast < void ( QgsMessageLog::* )( const QString &, const QString &, QgsMessageLog::MessageLevel ) >( &QgsMessageLog::messageReceived ),
46 }
47 
48 void QgsMessageLogConsole::logMessage( const QString &message, const QString &tag, QgsMessageLog::MessageLevel level )
49 {
50  std::cout
51  << tag.toLocal8Bit().data() << "[" <<
52  ( level == QgsMessageLog::INFO ? "INFO"
53  : level == QgsMessageLog::WARNING ? "WARNING"
54  : "CRITICAL" )
55  << "]: " << message.toLocal8Bit().data() << std::endl;
56 }
57 
Extends QApplication to provide access to QGIS specific resources such as theme paths, database paths etc.
#define QgsDebugMsg(str)
Definition: qgslogger.h:37
void messageReceived(const QString &message, const QString &tag, QgsMessageLog::MessageLevel level)
static QgsMessageLog * messageLog()
Returns the application&#39;s message log.
void logMessage(const QString &message, const QString &tag, QgsMessageLog::MessageLevel level)
Default implementation of message logging interface.
Definition: qgsmessagelog.h:79
static void logMessage(const QString &message, const QString &tag=QString(), MessageLevel level=QgsMessageLog::WARNING)
add a message to the instance (and create it if necessary)
Interface for logging messages from QGIS in GUI independent way.
Definition: qgsmessagelog.h:37