QGIS API Documentation 3.41.0-Master (cea29feecf2)
Loading...
Searching...
No Matches
qgsserverlogger.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsserverlogger.cpp
3 -------------------
4 begin : May 5, 2014
5 copyright : (C) 2014 by Marco Hugentobler
6 email : marco dot hugentobler at sourcepole dot ch
7 ***************************************************************************/
8
9/***************************************************************************
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 ***************************************************************************/
17
18#include "qgsserverlogger.h"
19#include "moc_qgsserverlogger.cpp"
20
21QgsServerLogger *QgsServerLogger::sInstance = nullptr;
22
24{
25 if ( !sInstance )
26 {
27 sInstance = new QgsServerLogger();
28 }
29 return sInstance;
30}
31
36
37void QgsServerLogger::logMessage( const QString &message, const QString &tag, Qgis::MessageLevel level )
38{
39 if ( mLogLevel > level )
40 {
41 return;
42 }
43 if ( mLogFile.isOpen() )
44 {
45 const QString formattedMessage = formatLogMessage( message, tag, level );
46 mTextStream << formattedMessage;
47 mTextStream.flush();
48 }
49 else if ( mLogStderr )
50 {
51 QgsMessageLogConsole::logMessage( message, tag, level );
52 }
53}
54
56{
57 mLogLevel = level;
58}
59
60void QgsServerLogger::setLogFile( const QString &filename )
61{
62 mTextStream.flush();
63 mLogFile.close();
64 mLogFile.setFileName( filename );
65
66 if ( ( !filename.isEmpty() ) && mLogFile.open( QIODevice::Append ) )
67 {
68 mTextStream.setDevice( &mLogFile );
69 }
70}
71
73{
74 setLogFile();
75 mLogStderr = true;
76}
MessageLevel
Level for messages This will be used both for message log and message bar in application.
Definition qgis.h:154
Default implementation of message logging interface.
QString formatLogMessage(const QString &message, const QString &tag, Qgis::MessageLevel level=Qgis::MessageLevel::Info) const
Formats a log message.
virtual void logMessage(const QString &message, const QString &tag, Qgis::MessageLevel level)
Logs a message to stderr.
Writes message log into server logfile.
static QgsServerLogger * instance()
Gets the singleton instance.
void setLogLevel(Qgis::MessageLevel level)
Set the current log level.
void setLogFile(const QString &filename=QString())
Set the current log file.
void setLogStderr()
Activates logging to stderr.
void logMessage(const QString &message, const QString &tag, Qgis::MessageLevel level) override
Log a message from the server context.