author | František Kučera <franta-hg@frantovo.cz> |
Wed, 27 Dec 2023 23:25:06 +0100 | |
branch | v_0 |
changeset 33 | 4620bba4fa40 |
parent 29 | dc3c102e1264 |
permissions | -rw-r--r-- |
0 | 1 |
/** |
29
dc3c102e1264
derive OHP3D from ShaderShark
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
2 |
* OHP3D |
0 | 3 |
* Copyright © 2023 František Kučera (Frantovo.cz, GlobalCode.info) |
4 |
* |
|
5 |
* This program is free software: you can redistribute it and/or modify |
|
6 |
* it under the terms of the GNU General Public License as published by |
|
7 |
* the Free Software Foundation, version 3 of the License. |
|
8 |
* |
|
9 |
* This program is distributed in the hope that it will be useful, |
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 |
* GNU General Public License for more details. |
|
13 |
* |
|
14 |
* You should have received a copy of the GNU General Public License |
|
15 |
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
16 |
*/ |
|
17 |
||
18 |
#pragma once |
|
19 |
||
20 |
#include <ostream> |
|
21 |
#include <string> |
|
22 |
||
23 |
#define LOG_LEVEL(XX) \ |
|
24 |
XX(OFF, 0, "OFF") \ |
|
25 |
XX(SEVERE, 1, "SEVERE") \ |
|
26 |
XX(WARNING, 2, "WARNING") \ |
|
27 |
XX(INFO, 3, "INFO") \ |
|
28 |
XX(CONFIG, 4, "CONFIG") \ |
|
29 |
XX(FINE, 5, "FINE") \ |
|
30 |
XX(FINER, 6, "FINER") \ |
|
31 |
XX(FINEST, 7, "FINEST") \ |
|
32 |
XX(ALL, 8, "ALL") |
|
33 |
||
34 |
enum class LogLevel { |
|
35 |
#define XX(a, b, c) a = (1 << b), |
|
36 |
LOG_LEVEL(XX) |
|
37 |
#undef XX |
|
38 |
}; |
|
39 |
||
40 |
static const char* LOG_LEVELS[] = { |
|
41 |
#define XX(a, b, c) [b] = c, |
|
42 |
LOG_LEVEL(XX) |
|
43 |
#undef XX |
|
44 |
}; |
|
45 |
||
46 |
#undef LOG_LEVEL |
|
47 |
||
48 |
#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) |
|
49 |
||
50 |
inline const char* getLogLevelName(LogLevel l) { |
|
51 |
auto count = ARRAY_SIZE(LOG_LEVELS); |
|
52 |
for (int i = 0; i < count; i++) if ((int) l == 1 << i) return LOG_LEVELS[i]; |
|
53 |
return nullptr; |
|
54 |
} |
|
55 |
||
56 |
inline void log(std::ostream& out, LogLevel level, std::string message) { |
|
57 |
out << getLogLevelName(level) << ": " << message << std::endl; |
|
58 |
} |