-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfastlog.h
54 lines (45 loc) · 1.4 KB
/
fastlog.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
//
// Created by Gabriele Gaetano Fronzé on 2019-11-06.
//
#ifndef LOGF_FASTLOG_H
#define LOGF_FASTLOG_H
#include <iostream>
#include <array>
#include <string>
namespace fastlog {
enum Level {
SILENT = 0,
ERROR = 1,
INFO = 2,
DEBUG = 3
} typedef Level;
extern Level logLevel;
static const std::array<std::string, 4> Colors
{
"",
"\x1B[1;31m[ERROR]\t", // ERROR: Bold Red
"\x1B[1;34m[INFO]\t", // INFO: Bold Blue
"\x1B[1;33m[DEBUG]\t" // DEBUG: Green
};
static void fastlog_internal(const Level level, const std::string s) {
std::FILE *output = (level == Level::ERROR ? stderr : stdout);
if (level <= logLevel) {
std::fprintf(output, "%s", Colors[level].data());
std::fprintf(output, "%s", s.data());
std::fprintf(output, "\x1B[0m");
std::fprintf(output, "\n");
}
}
template<typename... Args>
void fastlog_internal(const Level level, const std::string s, Args... args) {
std::FILE *output = (level == Level::ERROR ? stderr : stdout);
if (level <= logLevel) {
std::fprintf(output, "%s", Colors[level].data());
std::fprintf(output, s.data(), args...);
std::fprintf(output, "\x1B[0m");
std::fprintf(output, "\n");
}
}
}
#define fastlog(lvl, msg, ...) { fastlog_internal(lvl, "" msg, ##__VA_ARGS__); } (void)0
#endif //LOGF_FASTLOG_H