TTKMusicPlayer  3.7.0.0
TTKMusicPlayer imitates Kugou UI, the music player uses of qmmp core library based on Qt for windows and linux
ttklogger.h
Go to the documentation of this file.
1 #ifndef TTKLOGGER_H
2 #define TTKLOGGER_H
3 
4 /***************************************************************************
5  * This file is part of the TTK Library Module project
6  * Copyright (C) 2015 - 2024 Greedysky Studio
7 
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU Lesser General Public License as published by
10  * the Free Software Foundation; either version 3 of the License, or
11  * (at your option) any later version.
12 
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU Lesser General Public License for more details.
17 
18  * You should have received a copy of the GNU Lesser General Public License along
19  * with this program; If not, see <http://www.gnu.org/licenses/>.
20  ***************************************************************************/
21 
22 #include <QDebug>
23 #include <QDateTime>
24 
25 #if QT_VERSION < QT_VERSION_CHECK(5,4,0)
26 # define __TTK_LOG_OUTPUT__ qDebug()
27 #else
28 # define __TTK_LOG_OUTPUT__ qDebug().noquote()
29 #endif
30 
31 #define __TTK_DATE__ QDate::currentDate().toString("yyyy-MM-dd")
32 #define __TTK_TIME__ QTime::currentTime().toString("hh:mm:ss:zzz")
33 
34 // log stream base macro
35 #define __TTK_BASE_STREAM__(level, msg) __TTK_LOG_OUTPUT__ << QString("[%1 %2][%3][%4(%5)] ").arg(__TTK_DATE__, __TTK_TIME__, level, __FILE__, QString::number(__LINE__)) << msg
36 // log stream once base macro
37 #define __TTK_ONCE_STREAM__(level, msg) \
38  static bool __hit__ = false; \
39  if(!__hit__) \
40  { \
41  __hit__ = true; \
42  __TTK_BASE_STREAM__(level, msg); \
43  }
44 // log stream count base macro
45 #define __TTK_COUNT_STREAM__(count, level, msg) \
46  static __last__ = 1; \
47  if(count > 0 && ++__last__ > count) \
48  { \
49  __last__ = 1; \
50  __TTK_BASE_STREAM__(level, msg); \
51  }
52 // log stream period base macro
53 #define __TTK_PERIOD_STREAM__(period, level, msg) \
54  static qint64 __last__ = 0; \
55  const qint64 __now__ = QDateTime::currentMSecsSinceEpoch(); \
56  if(__last__ + period * 1000 <= __now__ || __now__ < __last__) \
57  { \
58  __last__ = __now__; \
59  __TTK_BASE_STREAM__(level, msg); \
60  }
61 
62 
63 #define TTK_LOG_STREAM(msg) __TTK_LOG_OUTPUT__ << msg
64 
65 #define TTK_TRACE_STREAM(msg) { __TTK_BASE_STREAM__("I", msg); }
66 #define TTK_DEBUG_STREAM(msg) { __TTK_BASE_STREAM__("D", msg); }
67 #define TTK_INFO_STREAM(msg) { __TTK_BASE_STREAM__("W", msg); }
68 #define TTK_WARN_STREAM(msg) { __TTK_BASE_STREAM__("T", msg); }
69 #define TTK_ERROR_STREAM(msg) { __TTK_BASE_STREAM__("E", msg); }
70 #define TTK_FATAL_STREAM(msg) { __TTK_BASE_STREAM__("F", msg); }
71 
72 #define TTK_TRACE_STREAM_ONCE(msg) { __TTK_ONCE_STREAM__("I", msg) }
73 #define TTK_DEBUG_STREAM_ONCE(msg) { __TTK_ONCE_STREAM__("D", msg) }
74 #define TTK_INFO_STREAM_ONCE(msg) { __TTK_ONCE_STREAM__("W", msg) }
75 #define TTK_WARN_STREAM_ONCE(msg) { __TTK_ONCE_STREAM__("T", msg) }
76 #define TTK_ERROR_STREAM_ONCE(msg) { __TTK_ONCE_STREAM__("E", msg) }
77 #define TTK_FATAL_STREAM_ONCE(msg) { __TTK_ONCE_STREAM__("F", msg) }
78 
79 #define TTK_TRACE_STREAM_COUNT(count, msg) { __TTK_COUNT_STREAM__(count, "I", msg) }
80 #define TTK_DEBUG_STREAM_COUNT(count, msg) { __TTK_COUNT_STREAM__(count, "D", msg) }
81 #define TTK_INFO_STREAM_COUNT(count, msg) { __TTK_COUNT_STREAM__(count, "W", msg) }
82 #define TTK_WARN_STREAM_COUNT(count, msg) { __TTK_COUNT_STREAM__(count, "T", msg) }
83 #define TTK_ERROR_STREAM_COUNT(count, msg) { __TTK_COUNT_STREAM__(count, "E", msg) }
84 #define TTK_FATAL_STREAM_COUNT(count, msg) { __TTK_COUNT_STREAM__(count, "F", msg) }
85 
86 #define TTK_TRACE_STREAM_PERIOD(period, msg) { __TTK_PERIOD_STREAM__(period, "I", msg) }
87 #define TTK_DEBUG_STREAM_PERIOD(period, msg) { __TTK_PERIOD_STREAM__(period, "D", msg) }
88 #define TTK_INFO_STREAM_PERIOD(period, msg) { __TTK_PERIOD_STREAM__(period, "W", msg) }
89 #define TTK_WARN_STREAM_PERIOD(period, msg) { __TTK_PERIOD_STREAM__(period, "T", msg) }
90 #define TTK_ERROR_STREAM_PERIOD(period, msg) { __TTK_PERIOD_STREAM__(period, "E", msg) }
91 #define TTK_FATAL_STREAM_PERIOD(period, msg) { __TTK_PERIOD_STREAM__(period, "F", msg) }
92 
93 #endif // TTKLOGGER_H