-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathlogger.cpp
71 lines (53 loc) · 1.72 KB
/
logger.cpp
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
#include "logger.h"
std::string g_cwd;
void Logger::init() {
char cwd[PATH_MAX];
if (getcwd(cwd, PATH_MAX) == NULL) {
g_cwd = "~";
}
g_cwd = cwd;
g_cwd.append("/");
#if LOGGER_CLEAR_ON_START
std::ofstream file(g_cwd + "hack.log", std::ios::out | std::ios::app);
// Clear the log file every time we start the hack
file.clear ();
#endif
normal ("Log path -> " + g_cwd);
}
void Logger::Log (std::string str) {
std::ofstream file(g_cwd + "hack.log", std::ios::out | std::ios::app);
str.append("\r\n");
if (file.good()) {
file << str;
}
file.close();
}
void Logger::normal(std::string str) {
Log (std::string("[LOG] ") + str);
std::cout << LOG_TITLE << RESET << str << RESET << std::endl;
}
void Logger::address (std::string str, unsigned long address) {
std::stringstream ss;
ss << std::hex << address;
Log (std::string("[ADDRESS] ") + str + ss.str ());
std::cout << ADDRESS_TITLE << RESET << str << BOLD CYAN " [" MAGENTA "0x" << std::hex << address << CYAN "]" << RESET << std::endl;
}
void Logger::warning (std::string str) {
Log (std::string("[WARNING] ") + str);
std::cout << ERROR_TITLE << YELLOW << str << RESET << std::endl;
}
void Logger::toggle (std::string feature, bool enabled) {
std::string endi = Endi (enabled);
Log (std::string("[TOGGLE] ") + feature + " " + endi);
std::cout << TOGGLE_TITLE << BOLD WHITE
<< feature << RESET BOLD CYAN "[ " << (enabled ? GREEN : RED)
<< endi << RESET BOLD << (enabled ? " " : " ") << CYAN << "]"
<< RESET << std::endl;
}
void Logger::error (std::string str) {
Log (std::string("[ERROR] ") + str);
std::cout << ERROR_TITLE << RED << str << RESET << std::endl;
}
std::string Logger::Endi (bool endi) {
return endi ? "Enabled" : "Disabled";
}