2
* This file is part of buteo-syncfw package
4
* Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
6
* Contact: Sateesh Kavuri <sateesh.kavuri@nokia.com>
8
* This library is free software; you can redistribute it and/or
9
* modify it under the terms of the GNU Lesser General Public License
10
* version 2.1 as published by the Free Software Foundation.
12
* This library is distributed in the hope that it will be useful, but
13
* WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
* Lesser General Public License for more details.
17
* You should have received a copy of the GNU Lesser General Public
18
* License along with this library; if not, write to the Free Software
19
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
35
#include <QTextStream>
41
* \brief A logger singleton class.
43
* Using the logger is thread safe, but creating the instance is not.
44
* Make sure that the instance is created before any threads that use the
45
* logger are started. This can be done by calling createInstance explicitly,
46
* or by simply logging some message, which will automatically create the
47
* logger instance with default parameters.
52
//! Possible logging levels.
55
// These are already defined in QtMsgType:
61
FIRST_CUSTOM_LEVEL = 4,
63
LEVEL_FATAL = FIRST_CUSTOM_LEVEL,
74
//! Default indent size.
75
static const int DEFAULT_INDENT_SIZE;
78
* \brief Returns the logger instance.
80
* If the instance is not yet created, creates it with default parameters.
81
* @return The instance.
83
static Logger *instance();
89
* \brief Creates a logger instance.
91
* If an instance already exists, deletes the old instance first.
92
* This function should be called in the beginning of the program
93
* before any threads using the logger are created, because creating
94
* the log instance is not thread safe.
95
* @param aLogFileName Name of the file where log messages are written.
96
* If this is empty, messages are not written to a file.
97
* @param aUseStdOut Should messages be written to standard output.
98
* @param aIndentSize Number of spaces that each indent level inserts.
100
static void createInstance(const QString &aLogFileName = "",
101
bool aUseStdOut = true,
102
int aIndentSize = DEFAULT_INDENT_SIZE);
104
//! Deletes the logger instance. Closes the log file in a controlled way.
105
static void deleteInstance();
108
* \brief Enables given log levels.
109
* @param aLevels Log levels to enable. Default enables all levels.
111
void enable(const QBitArray &aLevels = QBitArray(NUM_LEVELS, true));
114
* \brief Disables given log levels.
115
* @param aLevels Log levels to disable. Default disables all levels.
117
void disable(const QBitArray &aLevels = QBitArray(NUM_LEVELS, true));
120
* \brief Adds one indent level.
125
* \brief Removes one indent level.
130
* \brief Writes a message to the log.
132
* @param aLevel Message level.
133
* @param aMsg Message.
135
void write(int aLevel, const char *aMsg);
138
* \brief Sets logging level.
140
* Messages with the given level and levels more severe than it will be
141
* enabled. Qt built-in log levels will also be enabled.
142
* @param aLevel Logging level.
144
bool setLogLevel(int aLevel);
147
* \brief Gets logging level BitArray
149
* Use this API to count the levels the BitArray has been set to true
151
QBitArray getLogLevelArray();
154
Logger(const QString &aLogFileName, bool aUseStdOut, int aIndentSize);
156
static Logger *sInstance;
158
QBitArray iEnabledLevels;
166
QTextStream *iFileStream;
168
QTextStream *iStdOutStream;
170
QTextStream *iStdErrStream;