-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlogutil.h
45 lines (35 loc) · 1.65 KB
/
logutil.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
///
/// 2019-2021 Tong Zhang<[email protected]>
///
#ifndef _LOG_UTIL_
#define _LOG_UTIL_
#include "color.h"
#include <ctime>
#include <fstream>
#include <iostream>
#define outs() std::cout
#define errs() std::cerr
#define WARN(X) \
outs() << ANSI_COLOR_YELLOW << "WARN:" << X << ANSI_COLOR_RESET << "\n"
#define ERROR(X) \
outs() << ANSI_COLOR_RED << "ERROR:" << X << ANSI_COLOR_RESET << "\n"
#define INFO(X) outs() << ANSI_COLOR_RESET << "INFO:" << X << "\n"
#define unreachable(XXX) \
{ \
errs() << ANSI_COLOR_RED << __FILE__ << ":" << __LINE__ << " " << XXX \
<< ANSI_COLOR_RESET << "\n"; \
throw; \
}
#define hexval(X) "0x" << std::hex << (uintptr_t)X << std::dec
///
/// log to file -- append mode
///
#define LOG_TO_FILE(X, Y) \
if (1) { \
std::ofstream log; \
log.open(X, std::ofstream::out | std::ofstream::app); \
std::time_t result = std::time(nullptr); \
log << std::asctime(std::localtime(&result)) << Y << "\n"; \
log.close(); \
}
#endif