-
Notifications
You must be signed in to change notification settings - Fork 11
/
Log.h
61 lines (54 loc) · 1.94 KB
/
Log.h
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
#pragma once
#include <cstdarg>
#include <cstdio>
#if defined(_MSC_VER)
#include <sal.h>
#define CHECK_FORMAT_STRING(format_string_index_one_based, vargs_index_one_based)
#else
#define _Printf_format_string_
#define CHECK_FORMAT_STRING(format_string_index_one_based, vargs_index_one_based) \
__attribute__((format(printf, format_string_index_one_based, vargs_index_one_based)))
#endif
namespace Ray {
class ILog {
public:
virtual ~ILog() = default;
virtual void Info(_Printf_format_string_ const char *fmt, ...) CHECK_FORMAT_STRING(2, 3) = 0;
virtual void Warning(_Printf_format_string_ const char *fmt, ...) CHECK_FORMAT_STRING(2, 3) = 0;
virtual void Error(_Printf_format_string_ const char *fmt, ...) CHECK_FORMAT_STRING(2, 3) = 0;
};
class LogNull final : public ILog {
public:
void CHECK_FORMAT_STRING(2, 3) Info(_Printf_format_string_ const char *fmt, ...) override {}
void CHECK_FORMAT_STRING(2, 3) Warning(_Printf_format_string_ const char *fmt, ...) override {}
void CHECK_FORMAT_STRING(2, 3) Error(_Printf_format_string_ const char *fmt, ...) override {}
};
class LogStdout final : public Ray::ILog {
public:
void CHECK_FORMAT_STRING(2, 3) Info(_Printf_format_string_ const char *fmt, ...) override {
va_list vl;
va_start(vl, fmt);
vprintf(fmt, vl);
va_end(vl);
putc('\n', stdout);
}
void CHECK_FORMAT_STRING(2, 3) Warning(_Printf_format_string_ const char *fmt, ...) override {
va_list vl;
va_start(vl, fmt);
vprintf(fmt, vl);
va_end(vl);
putc('\n', stdout);
}
void CHECK_FORMAT_STRING(2, 3) Error(_Printf_format_string_ const char *fmt, ...) override {
va_list vl;
va_start(vl, fmt);
vprintf(fmt, vl);
va_end(vl);
putc('\n', stdout);
}
};
} // namespace Ray
#undef CHECK_FORMAT_STRING
#if !defined(_MSC_VER)
#undef _Printf_format_string_
#endif