32
|
1 |
/*
|
|
2 |
* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
* All rights reserved.
|
|
4 |
* This component and the accompanying materials are made available
|
|
5 |
* under the terms of "Eclipse Public License v1.0""
|
|
6 |
* which accompanies this distribution, and is available
|
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
8 |
*
|
|
9 |
* Initial Contributors:
|
|
10 |
* Nokia Corporation - initial contribution.
|
|
11 |
*
|
|
12 |
* Contributors:
|
|
13 |
*
|
|
14 |
* Description:
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
#ifndef LOGGER_H
|
|
19 |
#define LOGGER_H
|
|
20 |
|
|
21 |
#include <QObject>
|
|
22 |
#include <QSettings>
|
|
23 |
#include <loggerglobal.h>
|
|
24 |
|
|
25 |
class LogOutput;
|
|
26 |
class QSettings;
|
|
27 |
class LoggerPrivate;
|
|
28 |
|
|
29 |
/*
|
|
30 |
|
|
31 |
configuration format:
|
|
32 |
|
|
33 |
[myapplog]
|
|
34 |
logDateTime = 1
|
|
35 |
logLoggerName = 1
|
|
36 |
output = debugoutput consoleoutput fileoutput
|
|
37 |
fileoutput/logfile = C:/data/log/myapp.log
|
|
38 |
fileoutput/truncate = 1
|
|
39 |
|
|
40 |
code examples:
|
|
41 |
|
|
42 |
QSettings settings("myapp.ini",QSettings::IniFormat);
|
|
43 |
Logger::instance("myapplog")->configure(settings);
|
|
44 |
Logger::instance("myapplog")->log("Hello world!");
|
|
45 |
|
|
46 |
*/
|
|
47 |
|
|
48 |
class LOGGER_EXPORT Logger : public QObject
|
|
49 |
{
|
|
50 |
Q_OBJECT
|
|
51 |
Q_PROPERTY(bool logDateTime READ logDateTime WRITE setLogDateTime)
|
|
52 |
Q_PROPERTY(bool logLoggerName READ logLoggerName WRITE setLogLoggerName)
|
|
53 |
Q_PROPERTY(QString dateTimeFormat READ dateTimeFormat WRITE setDateTimeFormat)
|
|
54 |
public:
|
|
55 |
static Logger *instance(const QString &name);
|
|
56 |
static void close(const QString &name);
|
|
57 |
static void closeAll();
|
|
58 |
public:
|
|
59 |
virtual ~Logger();
|
|
60 |
|
|
61 |
void log(const QString &log);
|
|
62 |
|
|
63 |
void configure(const QString &configFile,QSettings::Format format = QSettings::NativeFormat);
|
|
64 |
|
|
65 |
void configure(QSettings &settings);
|
|
66 |
|
|
67 |
bool addLogOutput(LogOutput *output);
|
|
68 |
|
|
69 |
void removeLogOutput(LogOutput *output);
|
|
70 |
|
|
71 |
LogOutput *logOutput(const QString &name);
|
|
72 |
|
|
73 |
void clearAllLogOutput();
|
|
74 |
|
|
75 |
QString name() const;
|
|
76 |
|
|
77 |
bool logDateTime() const;
|
|
78 |
void setLogDateTime(bool on);
|
|
79 |
|
|
80 |
bool logLoggerName() const;
|
|
81 |
void setLogLoggerName(bool on);
|
|
82 |
|
|
83 |
QString dateTimeFormat() const;
|
|
84 |
void setDateTimeFormat(const QString &format);
|
|
85 |
private:
|
|
86 |
explicit Logger(const QString &name = QString(),QObject *parent = 0);
|
|
87 |
LoggerPrivate *d_ptr;
|
|
88 |
};
|
|
89 |
|
|
90 |
#endif //LOGGER_H
|