-
Notifications
You must be signed in to change notification settings - Fork 0
/
Logger.h
47 lines (40 loc) · 1.1 KB
/
Logger.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
#pragma once
#define NOMINMAX
#define WIN32_LEAN_AND_MEAN
#include <Windows.h>
#include <filesystem>
#include <iostream>
#include <cstdarg>
#include <string>
#include <memory>
class Logger {
public:
static Logger& get() noexcept {
static Logger s;
return s;
}
// Log the specified string with printf formatting options in the log file and console.
void log(std::string log, ...) noexcept {
va_list extra_args;
va_start(extra_args, log);
std::string fullLog = "dnll-injector: ";
fullLog += log + "\n";
if (Logger::logFile) {
vfprintf(Logger::logFile, fullLog.c_str(), extra_args);
fflush(Logger::logFile);
}
vprintf(fullLog.c_str(), extra_args);
va_end(extra_args);
}
// As Logger is a singleton, the assignment and copy operators are deleted.
Logger(const Logger&) = delete;
Logger& operator = (const Logger&) = delete;
private:
Logger() {
char path[MAX_PATH];
GetModuleFileNameA(NULL, path, MAX_PATH);
fopen_s(&Logger::logFile, (std::filesystem::path{ path }.parent_path().generic_string() + "/dnll-injector.log").c_str(), "w");
}
~Logger() {}
static inline FILE* logFile{};
};