Buteo Synchronization Framework: Logger.h Source File

Buteo Synchronization Framework

Logger.h
1 /*
2 * This file is part of buteo-syncfw package
3 *
4 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
5 *
6 * Contact: Sateesh Kavuri <sateesh.kavuri@nokia.com>
7 *
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.
11 *
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.
16 *
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
20 * 02110-1301 USA
21 *
22 */
23
24
25 #ifndef LOGGER_H
26 #define LOGGER_H
27
28 #include <QBitArray>
29 #include <QDebug>
30 #include <QFile>
31 #include <QList>
32 #include <QMutex>
33 #include <QString>
34 #include <QTextStream>
35
36
37 namespace Buteo {
38
48 class Q_DECL_EXPORT Logger
49 {
50 public:
51
52 static const int NUM_LEVELS = 4;
53
55 static const int DEFAULT_INDENT_SIZE;
56
63 static Logger *instance();
64
66 ~Logger();
67
80 static void createInstance(const QString &aLogFileName = "",
81 bool aUseStdOut = false,
82 int aIndentSize = DEFAULT_INDENT_SIZE);
83
85 static void deleteInstance();
86
91 void enable(const QBitArray &aLevels = QBitArray(NUM_LEVELS, true));
92
97 void disable(const QBitArray &aLevels = QBitArray(NUM_LEVELS, true));
98
102 void push();
103
107 void pop();
108
115 void write(int aLevel, const char *aMsg);
116
124 bool setLogLevel(int aLevel);
125
131 QBitArray getLogLevelArray();
132
136 int getLogLevel() const;
137
138 bool enabled()
139 {
140 return iEnabled;
141 }
142
143 private:
144 Logger(const QString &aLogFileName, bool aUseStdOut, int aIndentSize);
145
146 static int defaultLogLevel();
147
148 static Logger *sInstance;
149
150 QBitArray iEnabledLevels;
151 int iIndentLevel;
152 int iIndentSize;
153 QFile iFile;
154 QTextStream *iFileStream;
155 QTextStream *iStdOutStream;
156 QTextStream *iStdErrStream;
157 QMutex iMutex;
158 bool iEnabled;
159 int iLogLevel;
160 };
161
162 }
163
164 #endif // LOGGER_H
165
Buteo::Logger
A logger singleton class.
Definition: Logger.h:49
Buteo::Logger::DEFAULT_INDENT_SIZE
static const int DEFAULT_INDENT_SIZE
Default indent size.
Definition: Logger.h:55