QGIS API Documentation  2.99.0-Master (d55fa22)
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 
26  : QObject()
27 {
28  qRegisterMetaType< QgsMessageLog::MessageLevel >( "QgsMessageLog::MessageLevel" );
29 }
30 
31 void QgsMessageLog::logMessage( const QString &message, const QString &tag, QgsMessageLog::MessageLevel level )
32 {
33  QgsDebugMsg( QString( "%1 %2[%3] %4" ).arg( QDateTime::currentDateTime().toString( Qt::ISODate ), tag ).arg( level ).arg( message ) );
34 
35  QgsApplication::messageLog()->emitMessage( message, tag, level );
36 }
37 
38 void QgsMessageLog::emitMessage( const QString &message, const QString &tag, QgsMessageLog::MessageLevel level )
39 {
40  emit messageReceived( message, tag, level );
41  if ( level != QgsMessageLog::INFO )
42  {
43  emit messageReceived( true );
44  }
45 }
46 
48  : QObject( QgsApplication::messageLog() )
49 {
50  connect( QgsApplication::messageLog(), static_cast < void ( QgsMessageLog::* )( const QString &, const QString &, QgsMessageLog::MessageLevel ) >( &QgsMessageLog::messageReceived ),
52 }
53 
54 void QgsMessageLogConsole::logMessage( const QString &message, const QString &tag, QgsMessageLog::MessageLevel level )
55 {
56  std::cout
57  << tag.toLocal8Bit().data() << "[" <<
58  ( level == QgsMessageLog::INFO ? "INFO"
59  : level == QgsMessageLog::WARNING ? "WARNING"
60  : "CRITICAL" )
61  << "]: " << message.toLocal8Bit().data() << std::endl;
62 }
63 
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:74
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:36