2 * @file Common/logger.h
3 * @brief iLogger interface implementation
6 * Copyright (c) 2011 Enar Vaikene
8 * This file is part of the eVaf C++ cross-platform application development framework.
10 * This file can be used under the terms of the GNU General Public License
11 * version 3.0 as published by the Free Software Foundation and appearing in
12 * the file LICENSE included in the packaging of this file. Please review the
13 * the following information to ensure the GNU General Public License version
14 * 3.0 requirements will be met: http://www.gnu.org/copyleft/gpl.html.
16 * Alternatively, this file may be used in accordance with the Commercial License
17 * Agreement provided with the Software.
20 #ifndef __COMMON_LOGGER_H
21 #define __COMMON_LOGGER_H
32 /// Default fatal error message handler
33 void defFatalMsgHandler(QString
const & msg
, QString
const & source
, QString
const & where
);
38 * This class stores information about known sources.
40 class LoggerSource
: public QSharedData
46 LoggerSource(LoggerSource
const & o
);
49 * Initializes the source
50 * @param source Name of the source
51 * @param logDir Full path to the log directory
52 * @param etcDir Full path to the configuration files directory
54 * This function initializes the newly created logger source and sets initial
55 * parameters for the source.
58 * @li severity is set to Fatal
59 * @li maximum size of the log file is set to 100 KiB
60 * @li maximum number of log files is set to 3
62 * Default parameters can be overwritten with values read from the logger.ini file.
63 * This file should have the [.default] section with new default values for all the
64 * sources. Individual sources can have their parameters changed in sections with the
67 * Example logger.ini file:
80 void init(QString
const & source
, QString
const & logDir
, QString
const & etcDir
);
83 public: // Members (we don't bother adding getter/setter functions)
85 /// Current severity level
86 iLogger::Severity severity
;
88 /// Current log file name
91 /// Current maximum size of log files
94 /// Current maximum number of log files
100 * iLogger interface implementation.
102 * This class implements the iLogger interface.
104 class Logger
: public iLogger
115 * Initializes the interface implementation
116 * @return True if ok; false if initialization failed
124 virtual QString
defaultSource() const { return mDefaultSource
; }
126 virtual void setDefaultSource(QString
const & source
);
128 virtual Severity
severity(QString
const & source
= 0) const;
130 virtual void setSeverity(Severity severity
, QString
const & source
= 0);
132 virtual uint
maxSize(QString
const & source
= 0) const;
134 virtual void setMaxSize(uint maxSize
, QString
const & source
= 0);
136 virtual uint
maxCount(QString
const & source
= 0) const;
138 virtual void setMaxCount(uint maxCount
, QString
const & source
= 0);
140 virtual Severity
consoleSeverity() const { return mConsoleSeverity
; }
142 virtual void setConsoleSeverity(Severity severity
);
144 virtual void write(Severity severity
, QString
const & msg
, QString
const & source
= 0, QString
const & where
= 0);
146 virtual QString
printf(char const * const fmt
, ...) const;
148 virtual FatalMsgHandler
installFatalMsgHandler(FatalMsgHandler newHandler
);
153 /// Current fatal error message handler
154 FatalMsgHandler mFatalMsgHandler
;
156 /// Current default source (defaults to "evaf")
157 QString mDefaultSource
;
160 QHash
<QString
, QExplicitlySharedDataPointer
<LoggerSource
> > mSources
;
165 /// Returns the source by the name
166 LoggerSource
* getSource(QString
const & name
) const;
168 /// Creates a new source
169 LoggerSource
* addSource(QString
const & name
);
172 /// Changes text colors on the Windows console
173 void setColor(short int c
);
178 } // namespace eVaf::Common::Internal
179 } // namespace eVaf::Common