Skip to content
This repository was archived by the owner on Sep 24, 2018. It is now read-only.

Commit 3e1e0a0

Browse files
author
ZhangLongQi
committed
init
1 parent c20f898 commit 3e1e0a0

85 files changed

Lines changed: 10599 additions & 1 deletion

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.hg_archival.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
repo: 9a5455187e88c28e42b155c5e3749e8dd53551d2
2+
node: e6fe893e05f91fa31be46230ea1ad6e8fa2f7802
3+
branch: default
4+
latesttag: 0.4.4
5+
latesttagdistance: 1

.hgtags

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
d6d0b41b126ccba8b09fc59e48912745cfff75be 0.3b
2+
2381684f3d5aba19a8341f5066e8926836e75bd4 0.3.1
3+
777230899f8d2d6293ce086e5d8121d5633587a7 0.3.2
4+
823d2854d09feaeffa8b33bd26820c92b1c9338c 0.3.3
5+
6b8ac66401954f5095d78a8b69737b1d29fb3058 0.3.4
6+
05290da92610d4e7b0ca3408b797f60970fa5196 0.3.5
7+
bc07afceca77bac00b39f4524c323cf0762b0adf 0.3.6
8+
91b2f29aabda0f8a447e68701e3ec5290c975763 0.3.7
9+
e29486700476b695e2c06efe547047b50b7d1310 0.3.8
10+
cff1be19d097303526a5d08e482748af329b038a 0.3.9
11+
cb03b5cbb8acb10f3eb448ab5ce77cdf7bea2846 0.4.0
12+
193b3543cff470f065e492921634466938c31087 0.4.1
13+
e2f735cb82c448dc01b6930326ef207cc634334f 0.4.2
14+
0d5dd919458705c1452c6729fb4a81213ebc59ef 0.4.2-TC1
15+
daa66ad96e999b69a7891d6b1e88f283449eb658 0.4.3
16+
69ee0113d2939fdb453f3dad5fd8b4667cca22b5 0.4.4

3rdparty/QsLog/QsLog.cpp

Lines changed: 193 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,193 @@
1+
// Copyright (c) 2013, Razvan Petru
2+
// All rights reserved.
3+
4+
// Redistribution and use in source and binary forms, with or without modification,
5+
// are permitted provided that the following conditions are met:
6+
7+
// * Redistributions of source code must retain the above copyright notice, this
8+
// list of conditions and the following disclaimer.
9+
// * Redistributions in binary form must reproduce the above copyright notice, this
10+
// list of conditions and the following disclaimer in the documentation and/or other
11+
// materials provided with the distribution.
12+
// * The name of the contributors may not be used to endorse or promote products
13+
// derived from this software without specific prior written permission.
14+
15+
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
16+
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17+
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18+
// IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
19+
// INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
20+
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21+
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
22+
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
23+
// OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
24+
// OF THE POSSIBILITY OF SUCH DAMAGE.
25+
26+
#include "QsLog.h"
27+
#include "QsLogDest.h"
28+
#ifdef QS_LOG_SEPARATE_THREAD
29+
#include <QThreadPool>
30+
#include <QRunnable>
31+
#else
32+
#include <QMutex>
33+
#endif
34+
#include <QVector>
35+
#include <QDateTime>
36+
#include <QtGlobal>
37+
#include <cassert>
38+
#include <cstdlib>
39+
#include <stdexcept>
40+
41+
namespace QsLogging
42+
{
43+
typedef QVector<DestinationPtr> DestinationList;
44+
45+
static const char TraceString[] = "TRACE";
46+
static const char DebugString[] = "DEBUG";
47+
static const char InfoString[] = "INFO";
48+
static const char WarnString[] = "WARN";
49+
static const char ErrorString[] = "ERROR";
50+
static const char FatalString[] = "FATAL";
51+
52+
// not using Qt::ISODate because we need the milliseconds too
53+
static const QString fmtDateTime("yyyy-MM-ddThh:mm:ss.zzz");
54+
55+
static const char* LevelToText(Level theLevel)
56+
{
57+
switch (theLevel) {
58+
case TraceLevel:
59+
return TraceString;
60+
case DebugLevel:
61+
return DebugString;
62+
case InfoLevel:
63+
return InfoString;
64+
case WarnLevel:
65+
return WarnString;
66+
case ErrorLevel:
67+
return ErrorString;
68+
case FatalLevel:
69+
return FatalString;
70+
case OffLevel:
71+
return "";
72+
default: {
73+
assert(!"bad log level");
74+
return InfoString;
75+
}
76+
}
77+
}
78+
79+
#ifdef QS_LOG_SEPARATE_THREAD
80+
class LogWriterRunnable : public QRunnable
81+
{
82+
public:
83+
LogWriterRunnable(const QString &message, Level level)
84+
: mMessage(message)
85+
, mLevel(level) {}
86+
87+
virtual void run()
88+
{
89+
Logger::instance().write(mMessage, mLevel);
90+
}
91+
92+
private:
93+
QString mMessage;
94+
Level mLevel;
95+
};
96+
#endif
97+
98+
class LoggerImpl
99+
{
100+
public:
101+
LoggerImpl() :
102+
level(InfoLevel)
103+
{
104+
// assume at least file + console
105+
destList.reserve(2);
106+
#ifdef QS_LOG_SEPARATE_THREAD
107+
threadPool.setMaxThreadCount(1);
108+
threadPool.setExpiryTimeout(-1);
109+
#endif
110+
}
111+
#ifdef QS_LOG_SEPARATE_THREAD
112+
QThreadPool threadPool;
113+
#else
114+
QMutex logMutex;
115+
#endif
116+
Level level;
117+
DestinationList destList;
118+
};
119+
120+
Logger::Logger() :
121+
d(new LoggerImpl)
122+
{
123+
}
124+
125+
Logger::~Logger()
126+
{
127+
delete d;
128+
}
129+
130+
void Logger::addDestination(DestinationPtr destination)
131+
{
132+
assert(destination.data());
133+
d->destList.push_back(destination);
134+
}
135+
136+
void Logger::setLoggingLevel(Level newLevel)
137+
{
138+
d->level = newLevel;
139+
}
140+
141+
Level Logger::loggingLevel() const
142+
{
143+
return d->level;
144+
}
145+
146+
//! creates the complete log message and passes it to the logger
147+
void Logger::Helper::writeToLog()
148+
{
149+
const char* const levelName = LevelToText(level);
150+
const QString completeMessage(QString("%1 %2 %3")
151+
.arg(levelName, 5)
152+
.arg(QDateTime::currentDateTime().toString(fmtDateTime))
153+
.arg(buffer)
154+
);
155+
156+
Logger::instance().enqueueWrite(completeMessage, level);
157+
}
158+
159+
Logger::Helper::~Helper()
160+
{
161+
try {
162+
writeToLog();
163+
}
164+
catch(std::exception&) {
165+
// you shouldn't throw exceptions from a sink
166+
assert(!"exception in logger helper destructor");
167+
throw;
168+
}
169+
}
170+
171+
//! directs the message to the task queue or writes it directly
172+
void Logger::enqueueWrite(const QString& message, Level level)
173+
{
174+
#ifdef QS_LOG_SEPARATE_THREAD
175+
LogWriterRunnable *r = new LogWriterRunnable(message, level);
176+
d->threadPool.start(r);
177+
#else
178+
QMutexLocker lock(&d->logMutex);
179+
write(message, level);
180+
#endif
181+
}
182+
183+
//! Sends the message to all the destinations. The level for this message is passed in case
184+
//! it's useful for processing in the destination.
185+
void Logger::write(const QString& message, Level level)
186+
{
187+
for (DestinationList::iterator it = d->destList.begin(),
188+
endIt = d->destList.end();it != endIt;++it) {
189+
(*it)->write(message, level);
190+
}
191+
}
192+
193+
} // end namespace

3rdparty/QsLog/QsLog.h

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
// Copyright (c) 2013, Razvan Petru
2+
// All rights reserved.
3+
4+
// Redistribution and use in source and binary forms, with or without modification,
5+
// are permitted provided that the following conditions are met:
6+
7+
// * Redistributions of source code must retain the above copyright notice, this
8+
// list of conditions and the following disclaimer.
9+
// * Redistributions in binary form must reproduce the above copyright notice, this
10+
// list of conditions and the following disclaimer in the documentation and/or other
11+
// materials provided with the distribution.
12+
// * The name of the contributors may not be used to endorse or promote products
13+
// derived from this software without specific prior written permission.
14+
15+
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
16+
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17+
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18+
// IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
19+
// INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
20+
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21+
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
22+
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
23+
// OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
24+
// OF THE POSSIBILITY OF SUCH DAMAGE.
25+
26+
#ifndef QSLOG_H
27+
#define QSLOG_H
28+
29+
#include "QsLogLevel.h"
30+
#include "QsLogDest.h"
31+
#include <QDebug>
32+
#include <QString>
33+
34+
#define QS_LOG_VERSION "2.0b1"
35+
36+
namespace QsLogging
37+
{
38+
class Destination;
39+
class LoggerImpl; // d pointer
40+
41+
class Logger
42+
{
43+
public:
44+
static Logger& instance()
45+
{
46+
static Logger staticLog;
47+
return staticLog;
48+
}
49+
50+
//! Adds a log message destination. Don't add null destinations.
51+
void addDestination(DestinationPtr destination);
52+
//! Logging at a level < 'newLevel' will be ignored
53+
void setLoggingLevel(Level newLevel);
54+
//! The default level is INFO
55+
Level loggingLevel() const;
56+
57+
//! The helper forwards the streaming to QDebug and builds the final
58+
//! log message.
59+
class Helper
60+
{
61+
public:
62+
explicit Helper(Level logLevel) :
63+
level(logLevel),
64+
qtDebug(&buffer) {}
65+
~Helper();
66+
QDebug& stream(){ return qtDebug; }
67+
68+
private:
69+
void writeToLog();
70+
71+
Level level;
72+
QString buffer;
73+
QDebug qtDebug;
74+
};
75+
76+
private:
77+
Logger();
78+
Logger(const Logger&);
79+
Logger& operator=(const Logger&);
80+
~Logger();
81+
82+
void enqueueWrite(const QString& message, Level level);
83+
void write(const QString& message, Level level);
84+
85+
LoggerImpl* d;
86+
87+
friend class LogWriterRunnable;
88+
};
89+
90+
} // end namespace
91+
92+
//! Logging macros: define QS_LOG_LINE_NUMBERS to get the file and line number
93+
//! in the log output.
94+
#ifndef QS_LOG_LINE_NUMBERS
95+
#define QLOG_TRACE() \
96+
if (QsLogging::Logger::instance().loggingLevel() > QsLogging::TraceLevel) {} \
97+
else QsLogging::Logger::Helper(QsLogging::TraceLevel).stream()
98+
#define QLOG_DEBUG() \
99+
if (QsLogging::Logger::instance().loggingLevel() > QsLogging::DebugLevel) {} \
100+
else QsLogging::Logger::Helper(QsLogging::DebugLevel).stream()
101+
#define QLOG_INFO() \
102+
if (QsLogging::Logger::instance().loggingLevel() > QsLogging::InfoLevel) {} \
103+
else QsLogging::Logger::Helper(QsLogging::InfoLevel).stream()
104+
#define QLOG_WARN() \
105+
if (QsLogging::Logger::instance().loggingLevel() > QsLogging::WarnLevel) {} \
106+
else QsLogging::Logger::Helper(QsLogging::WarnLevel).stream()
107+
#define QLOG_ERROR() \
108+
if (QsLogging::Logger::instance().loggingLevel() > QsLogging::ErrorLevel) {} \
109+
else QsLogging::Logger::Helper(QsLogging::ErrorLevel).stream()
110+
#define QLOG_FATAL() \
111+
if (QsLogging::Logger::instance().loggingLevel() > QsLogging::FatalLevel) {} \
112+
else QsLogging::Logger::Helper(QsLogging::FatalLevel).stream()
113+
#else
114+
#define QLOG_TRACE() \
115+
if (QsLogging::Logger::instance().loggingLevel() > QsLogging::TraceLevel) {} \
116+
else QsLogging::Logger::Helper(QsLogging::TraceLevel).stream() << __FILE__ << '@' << __LINE__
117+
#define QLOG_DEBUG() \
118+
if (QsLogging::Logger::instance().loggingLevel() > QsLogging::DebugLevel) {} \
119+
else QsLogging::Logger::Helper(QsLogging::DebugLevel).stream() << __FILE__ << '@' << __LINE__
120+
#define QLOG_INFO() \
121+
if (QsLogging::Logger::instance().loggingLevel() > QsLogging::InfoLevel) {} \
122+
else QsLogging::Logger::Helper(QsLogging::InfoLevel).stream() << __FILE__ << '@' << __LINE__
123+
#define QLOG_WARN() \
124+
if (QsLogging::Logger::instance().loggingLevel() > QsLogging::WarnLevel) {} \
125+
else QsLogging::Logger::Helper(QsLogging::WarnLevel).stream() << __FILE__ << '@' << __LINE__
126+
#define QLOG_ERROR() \
127+
if (QsLogging::Logger::instance().loggingLevel() > QsLogging::ErrorLevel) {} \
128+
else QsLogging::Logger::Helper(QsLogging::ErrorLevel).stream() << __FILE__ << '@' << __LINE__
129+
#define QLOG_FATAL() \
130+
if (QsLogging::Logger::instance().loggingLevel() > QsLogging::FatalLevel) {} \
131+
else QsLogging::Logger::Helper(QsLogging::FatalLevel).stream() << __FILE__ << '@' << __LINE__
132+
#endif
133+
134+
#ifdef QS_LOG_DISABLE
135+
#include "QsLogDisableForThisFile.h"
136+
#endif
137+
138+
#endif // QSLOG_H

3rdparty/QsLog/QsLog.pri

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
INCLUDEPATH += $$PWD
2+
#DEFINES += QS_LOG_LINE_NUMBERS # automatically writes the file and line for each log message
3+
#DEFINES += QS_LOG_DISABLE # logging code is replaced with a no-op
4+
#DEFINES += QS_LOG_SEPARATE_THREAD # messages are queued and written from a separate thread
5+
SOURCES += $$PWD/QsLogDest.cpp \
6+
$$PWD/QsLog.cpp \
7+
$$PWD/QsLogDestConsole.cpp \
8+
$$PWD/QsLogDestFile.cpp
9+
10+
HEADERS += $$PWD/QSLogDest.h \
11+
$$PWD/QsLog.h \
12+
$$PWD/QsLogDestConsole.h \
13+
$$PWD/QsLogLevel.h \
14+
$$PWD/QsLogDestFile.h \
15+
$$PWD/QsLogDisableForThisFile.h
16+
17+
OTHER_FILES += \
18+
$$PWD/QsLogChanges.txt \
19+
$$PWD/QsLogReadme.txt

3rdparty/QsLog/QsLogChanges.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
QsLog version 2.0b1
2+
3+
Changes:
4+
* destination pointers use shared pointer semantics
5+
* the file destination supports log rotation. As a consequence, log files are encoded as UTF-8 and
6+
the log appends rather than truncating on every startup when rotation is enabled.
7+
* added the posibility of disabling logging either at run time or compile time.
8+
* added the possibility of using a separate thread for writing to the log destinations.
9+
10+
Fixes:
11+
* renamed the main.cpp example to avoid QtCreator confusion
12+
* offer a way to check if the destination creation has failed (for e.g files)

0 commit comments

Comments
 (0)