QGIS API Documentation  3.0.2-Girona (307d082)
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, Qgis::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, Qgis::MessageLevel level )
33 {
34  emit messageReceived( message, tag, level );
35  if ( level != Qgis::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 &, Qgis::MessageLevel ) >( &QgsMessageLog::messageReceived ),
46 }
47 
48 void QgsMessageLogConsole::logMessage( const QString &message, const QString &tag, Qgis::MessageLevel level )
49 {
50  std::cout
51  << tag.toLocal8Bit().data() << "[" <<
52  ( level == Qgis::Info ? "INFO"
53  : level == Qgis::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:38
void messageReceived(const QString &message, const QString &tag, Qgis::MessageLevel level)
MessageLevel
Level for messages This will be used both for message log and message bar in application.
Definition: qgis.h:78
static void logMessage(const QString &message, const QString &tag=QString(), Qgis::MessageLevel level=Qgis::Warning)
add a message to the instance (and create it if necessary)
static QgsMessageLog * messageLog()
Returns the application&#39;s message log.
void logMessage(const QString &message, const QString &tag, Qgis::MessageLevel level)
Default implementation of message logging interface.
Definition: qgsmessagelog.h:70
Interface for logging messages from QGIS in GUI independent way.
Definition: qgsmessagelog.h:38