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