-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlog.hpp
More file actions
110 lines (81 loc) · 3.4 KB
/
Copy pathlog.hpp
File metadata and controls
110 lines (81 loc) · 3.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
// === (C) 2020 === parallel_f / log (tasks, queues, lists in parallel threads)
// Written by Denis Oliver Kropp <Leichenbegatter@outlook.com>
#pragma once
#include "system.hpp"
#include "ustd.hpp"
// parallel_f :: log == implementation
namespace parallel_f {
#define PARALLEL_F__LOG(Sym) \
do { \
unsigned int ms = system::localtime_ms(); \
\
char buf[1024]; \
\
va_list args; \
va_start(args, fmt); \
vsnprintf(buf, sizeof(buf), fmt, args); \
va_end(args); \
\
std::stringstream tid; \
tid << std::this_thread::get_id(); \
\
system::instance().log("(" #Sym ") [%02d:%02d:%02d.%03d] (%5s) %s", \
ms / 1000 / 60 / 60, ms / 1000 / 60 % 60, \
ms / 1000 % 60, ms % 1000, tid.str().c_str(), buf); \
} while (0)
#define PARALLEL_F__ENABLE_DEBUG
#ifndef NDEBUG
#define NDEBUG (0)
#endif
#ifdef PARALLEL_F__ENABLE_DEBUG
#if NDEBUG
#define PARALLEL_F__DEBUG_ENABLED (0)
#else
#define PARALLEL_F__DEBUG_ENABLED (1)
#endif
#else
#define PARALLEL_F__DEBUG_ENABLED (0)
#endif
#if PARALLEL_F__DEBUG_ENABLED
#define LOG_DEBUG(...) parallel_f::log_debug(__VA_ARGS__)
#else
#define LOG_DEBUG(...) \
do { \
} while (0)
#endif
#define LOG_INFO(...) parallel_f::log_info_f(__VA_ARGS__)
#define LOG_ERROR(...) parallel_f::log_error(__VA_ARGS__)
static inline void log_debug(const char *fmt, ...) {
if (get_debug_level() == 0 && get_debug_level(fmt) == 0)
return;
PARALLEL_F__LOG(-);
}
static inline void log_debug_f(const char *fmt, ...) {
if (get_debug_level() == 0 && get_debug_level(fmt) == 0)
return;
PARALLEL_F__LOG(-);
system::instance().flush();
}
static inline void log_info(const char *fmt, ...) { PARALLEL_F__LOG(*); }
static inline void log_info_f(const char *fmt, ...) {
PARALLEL_F__LOG(*);
system::instance().flush();
}
static inline void log_error(const char *fmt, ...) {
PARALLEL_F__LOG(!!!);
system::instance().flush();
}
template <typename ArgType> static inline std::string log_string(ArgType arg) {
return ustd::to_string(arg);
}
template <> inline std::string log_string(const char *arg) { return arg; }
template <typename... Args> static inline void log_line(Args... args) {
std::string line;
(line.append(log_string(args)), ...);
system::instance().log("%s\n", line.c_str());
}
template <typename... Args> static inline void log_line_f(Args... args) {
log_line<Args...>(args...);
system::instance().flush();
}
} // namespace parallel_f