-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLog.cc
More file actions
43 lines (37 loc) · 1.18 KB
/
Log.cc
File metadata and controls
43 lines (37 loc) · 1.18 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
#include <iostream>
#include <string>
#include "Color.hh"
#include "Log.hh"
namespace pcc {
void Log(LogLevel level, const char* format, ...) {
char buf[1024];
va_list va;
va_start(va, format);
if (GetLogLevel() <= level) {
std::cerr << GetExecutableName() << ": ";
switch (level) {
case PCC_ERROR:
std::cerr << Color::RED << "error: ";
break;
case PCC_WARNING:
std::cerr << Color::MAGENTA << "warning: ";
break;
case PCC_INFO:
std::cerr << Color::CYAN << "info: ";
break;
case PCC_DEBUG:
std::cerr << Color::GREEN << "remark: ";
break;
}
std::vsnprintf(buf, sizeof(buf), format, va);
std::cerr << Color::WHITE << buf << Color::DEFAULT << std::endl;
}
va_end(va);
}
static LogLevel CurrentLogLevel = PCC_ERROR;
void SetLogLevel(LogLevel level) { CurrentLogLevel = level; }
LogLevel GetLogLevel() { return CurrentLogLevel; }
static std::string Executable("pcc");
void SetExecutableName(const char* name) { Executable = name; }
const char* GetExecutableName() { return Executable.c_str(); }
} // namespace pcc