TTKMusicPlayer  4.2.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 - 2025 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 #include "ttkglobal.h"
25 
26 #if QT_VERSION < QT_VERSION_CHECK(5,4,0)
27 # define __TTK_LOG_OUTPUT__ qDebug()
28 #else
29 # define __TTK_LOG_OUTPUT__ qDebug().noquote()
30 #endif
31 
32 #define __TTK_DATE__ QDate::currentDate().toString(TTK_DATE_FORMAT)
33 #define __TTK_TIME__ QTime::currentTime().toString(TTK_TIMEZ_FORMAT)
34 
35 // log stream base macro
36 #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
37 // log stream once base macro
38 #define __TTK_ONCE_STREAM__(level, msg) \
39  static bool __hit__ = false; \
40  if(!__hit__) \
41  { \
42  __hit__ = true; \
43  __TTK_BASE_STREAM__(level, msg); \
44  }
45 // log stream condition base macro
46 #define __TTK_COND_STREAM__(cond, level, msg) \
47  if(cond) \
48  { \
49  __TTK_BASE_STREAM__(level, msg); \
50  }
51 // log stream count base macro
52 #define __TTK_COUNT_STREAM__(count, level, msg) \
53  static int __last__ = 1; \
54  if(count > 0 && ++__last__ > count) \
55  { \
56  __last__ = 1; \
57  __TTK_BASE_STREAM__(level, msg); \
58  }
59 // log stream period base macro
60 #define __TTK_PERIOD_STREAM__(period, level, msg) \
61  static qint64 __last__ = 0; \
62  const qint64 __now__ = QDateTime::currentMSecsSinceEpoch(); \
63  if(__last__ + period * 1000 <= __now__ || __now__ < __last__) \
64  { \
65  __last__ = __now__; \
66  __TTK_BASE_STREAM__(level, msg); \
67  }
68 
69 
70 #define TTK_LOG_STREAM(msg) __TTK_LOG_OUTPUT__ << msg
71 
72 #define TTK_TRACE_STREAM(msg) { __TTK_BASE_STREAM__("T", msg); }
73 #define TTK_DEBUG_STREAM(msg) { __TTK_BASE_STREAM__("D", msg); }
74 #define TTK_INFO_STREAM(msg) { __TTK_BASE_STREAM__("I", msg); }
75 #define TTK_WARN_STREAM(msg) { __TTK_BASE_STREAM__("W", msg); }
76 #define TTK_ERROR_STREAM(msg) { __TTK_BASE_STREAM__("E", msg); }
77 #define TTK_FATAL_STREAM(msg) { __TTK_BASE_STREAM__("F", msg); }
78 
79 #define TTK_TRACE_STREAM_ONCE(msg) { __TTK_ONCE_STREAM__("T", msg) }
80 #define TTK_DEBUG_STREAM_ONCE(msg) { __TTK_ONCE_STREAM__("D", msg) }
81 #define TTK_INFO_STREAM_ONCE(msg) { __TTK_ONCE_STREAM__("I", msg) }
82 #define TTK_WARN_STREAM_ONCE(msg) { __TTK_ONCE_STREAM__("W", msg) }
83 #define TTK_ERROR_STREAM_ONCE(msg) { __TTK_ONCE_STREAM__("E", msg) }
84 #define TTK_FATAL_STREAM_ONCE(msg) { __TTK_ONCE_STREAM__("F", msg) }
85 
86 #define TTK_TRACE_STREAM_COND(cond, msg) { __TTK_COND_STREAM__(cond, "T", msg) }
87 #define TTK_DEBUG_STREAM_COND(cond, msg) { __TTK_COND_STREAM__(cond, "D", msg) }
88 #define TTK_INFO_STREAM_COND(cond, msg) { __TTK_COND_STREAM__(cond, "I", msg) }
89 #define TTK_WARN_STREAM_COND(cond, msg) { __TTK_COND_STREAM__(cond, "W", msg) }
90 #define TTK_ERROR_STREAM_COND(cond, msg) { __TTK_COND_STREAM__(cond, "E", msg) }
91 #define TTK_FATAL_STREAM_COND(cond, msg) { __TTK_COND_STREAM__(cond, "F", msg) }
92 
93 #define TTK_TRACE_STREAM_COUNT(count, msg) { __TTK_COUNT_STREAM__(count, "T", msg) }
94 #define TTK_DEBUG_STREAM_COUNT(count, msg) { __TTK_COUNT_STREAM__(count, "D", msg) }
95 #define TTK_INFO_STREAM_COUNT(count, msg) { __TTK_COUNT_STREAM__(count, "I", msg) }
96 #define TTK_WARN_STREAM_COUNT(count, msg) { __TTK_COUNT_STREAM__(count, "W", msg) }
97 #define TTK_ERROR_STREAM_COUNT(count, msg) { __TTK_COUNT_STREAM__(count, "E", msg) }
98 #define TTK_FATAL_STREAM_COUNT(count, msg) { __TTK_COUNT_STREAM__(count, "F", msg) }
99 
100 #define TTK_TRACE_STREAM_PERIOD(period, msg) { __TTK_PERIOD_STREAM__(period, "T", msg) }
101 #define TTK_DEBUG_STREAM_PERIOD(period, msg) { __TTK_PERIOD_STREAM__(period, "D", msg) }
102 #define TTK_INFO_STREAM_PERIOD(period, msg) { __TTK_PERIOD_STREAM__(period, "I", msg) }
103 #define TTK_WARN_STREAM_PERIOD(period, msg) { __TTK_PERIOD_STREAM__(period, "W", msg) }
104 #define TTK_ERROR_STREAM_PERIOD(period, msg) { __TTK_PERIOD_STREAM__(period, "E", msg) }
105 #define TTK_FATAL_STREAM_PERIOD(period, msg) { __TTK_PERIOD_STREAM__(period, "F", msg) }
106 
107 #endif // TTKLOGGER_H