Skip to content

Commit a2d52cf

Browse files
style: add some comment for log
1 parent 1181b77 commit a2d52cf

File tree

3 files changed

+51
-6
lines changed

3 files changed

+51
-6
lines changed

makespec/BUILDVERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
134
1+
136

src/base/LemonLog.hpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,28 @@
1111
#include <QString>
1212
#include <QTextStream>
1313
#include <iostream>
14+
//
15+
#include <base/LemonMacro.hpp>
16+
#include <base/LemonBaseApplication.hpp>
1417

1518
#define NEWLINE "\r\n"
16-
#define ___LOG_EXPAND(___x) \
17-
, std::pair { \
18-
#___x, [&] { return ___x; }() \
19-
}
19+
#define ___LOG_EXPAND(___x) , QPair<std::string, decltype(___x)>(std::string(#___x), [&] { return ___x; }())
20+
21+
// Generate pairs for each variable passed as args to use in the log.
22+
// with line 73: QTextStream &operator<<(QTextStream &stream, const std::pair<TKey, TVal> &pair)
2023
#define A(...) FOREACH_CALL_FUNC(___LOG_EXPAND, __VA_ARGS__)
2124

2225
#ifdef QT_DEBUG
2326
#define LEMON_IS_DEBUG true
2427
// __FILE__ ":" QT_STRINGIFY(__LINE__),
28+
// https://doc.qt.io/qt-5/qtglobal.html#Q_FUNC_INFO
2529
#define LEMON_LOG_PREPEND_CONTENT Q_FUNC_INFO,
2630
#else
2731
#define LEMON_IS_DEBUG false
2832
#define LEMON_LOG_PREPEND_CONTENT
2933
#endif
3034

35+
// prepend module name in log
3136
#define _LOG_ARG_(...) LEMON_LOG_PREPEND_CONTENT "[" LEMON_MODULE_NAME "]", __VA_ARGS__
3237

3338
#define LOG(...) Lemon::base::log_concat<LEMON_LOG_NORMAL>(_LOG_ARG_(__VA_ARGS__))
@@ -51,7 +56,7 @@ namespace Lemon::base {
5156
logStream << NEWLINE;
5257
#ifndef QT_DEBUG
5358
// We only process DEBUG log in Release mode
54-
if (t == LEMON_LOG_DEBUG /* && !StartupOption.debugLog */) {
59+
if (t == LEMON_LOG_DEBUG && LemonBaseApplication && !LemonBaseApplication->StartupArguments.debugLog) {
5560
// Discard debug log in non-debug Lemon version with
5661
// no-debugLog mode.
5762
return;

src/base/LemonMacro.hpp

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* SPDX-FileCopyrightText: 2020-2021 Project LemonLime
3+
*
4+
* SPDX-License-Identifier: GPL-3.0-or-later
5+
*
6+
*/
7+
8+
9+
#pragma once
10+
11+
#define CONCATENATE1(arg1, arg2) CONCATENATE2(arg1, arg2)
12+
#define CONCATENATE2(arg1, arg2) arg1##arg2
13+
#define CONCATENATE(x, y) x##y
14+
15+
#define EXPAND(...) __VA_ARGS__
16+
#define FOR_EACH_1(what, x, ...) what(x)
17+
#define FOR_EACH_2(what, x, ...) what(x) EXPAND(FOR_EACH_1(what, __VA_ARGS__))
18+
#define FOR_EACH_3(what, x, ...) what(x) EXPAND(FOR_EACH_2(what, __VA_ARGS__))
19+
#define FOR_EACH_4(what, x, ...) what(x) EXPAND(FOR_EACH_3(what, __VA_ARGS__))
20+
#define FOR_EACH_5(what, x, ...) what(x) EXPAND(FOR_EACH_4(what, __VA_ARGS__))
21+
#define FOR_EACH_6(what, x, ...) what(x) EXPAND(FOR_EACH_5(what, __VA_ARGS__))
22+
#define FOR_EACH_7(what, x, ...) what(x) EXPAND(FOR_EACH_6(what, __VA_ARGS__))
23+
#define FOR_EACH_8(what, x, ...) what(x) EXPAND(FOR_EACH_7(what, __VA_ARGS__))
24+
#define FOR_EACH_9(what, x, ...) what(x) EXPAND(FOR_EACH_8(what, __VA_ARGS__))
25+
#define FOR_EACH_10(what, x, ...) what(x) EXPAND(FOR_EACH_9(what, __VA_ARGS__))
26+
#define FOR_EACH_11(what, x, ...) what(x) EXPAND(FOR_EACH_10(what, __VA_ARGS__))
27+
#define FOR_EACH_12(what, x, ...) what(x) EXPAND(FOR_EACH_11(what, __VA_ARGS__))
28+
#define FOR_EACH_13(what, x, ...) what(x) EXPAND(FOR_EACH_12(what, __VA_ARGS__))
29+
#define FOR_EACH_14(what, x, ...) what(x) EXPAND(FOR_EACH_13(what, __VA_ARGS__))
30+
#define FOR_EACH_15(what, x, ...) what(x) EXPAND(FOR_EACH_14(what, __VA_ARGS__))
31+
#define FOR_EACH_16(what, x, ...) what(x) EXPAND(FOR_EACH_15(what, __VA_ARGS__))
32+
33+
#define FOR_EACH_NARG(...) FOR_EACH_NARG_(__VA_ARGS__, FOR_EACH_RSEQ_N())
34+
#define FOR_EACH_NARG_(...) EXPAND(FOR_EACH_ARG_N(__VA_ARGS__))
35+
#define FOR_EACH_ARG_N(_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, N, ...) N
36+
#define FOR_EACH_RSEQ_N() 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0
37+
38+
#define FOR_EACH_(N, what, ...) EXPAND(CONCATENATE(FOR_EACH_, N)(what, __VA_ARGS__))
39+
#define FOR_EACH(what, ...) FOR_EACH_(FOR_EACH_NARG(__VA_ARGS__), what, __VA_ARGS__)
40+
#define FOREACH_CALL_FUNC(func, ...) FOR_EACH(func, __VA_ARGS__)

0 commit comments

Comments
 (0)