Skip to content

Commit 16f757d

Browse files
committed
Utils
- Custom allocator of memory (allocates near game memory) - LRU Cache - Formatting
1 parent 64e2fb6 commit 16f757d

File tree

10 files changed

+906
-395
lines changed

10 files changed

+906
-395
lines changed

src/Utils/Logger/Logger.cpp

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,74 +6,63 @@
66
#include <fstream>
77
#include <iostream>
88

9-
std::string Logger::file = Utils::getRoamingPath() + "\\Flarial\\logs\\latest.log";
9+
std::string Logger::file = Utils::getRoamingPath() + R"(\Flarial\logs\latest.log)";
1010

11-
void Logger::writeToFile(std::string str)
12-
{
11+
void Logger::writeToFile(const std::string& str) {
1312

14-
if (std::filesystem::exists(file))
15-
{
13+
if (std::filesystem::exists(file)) {
1614
std::filesystem::path p(file);
1715
std::filesystem::create_directories(p.parent_path().string());
1816
}
1917

2018
CloseHandle(CreateFileA(file.c_str(), GENERIC_WRITE | GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, nullptr,
2119
OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr));
2220

23-
if (str.length() > 0)
24-
{
21+
if (!str.empty()) {
2522
std::ofstream fileOutput;
2623
fileOutput.open(file.c_str(), std::ios_base::app);
2724
fileOutput << str << std::endl;
2825
fileOutput.close();
2926
}
3027
}
3128

32-
void Logger::initialize()
33-
{
34-
if (std::filesystem::exists(file))
35-
{
29+
void Logger::initialize() {
30+
if (std::filesystem::exists(file)) {
3631
std::filesystem::remove(file);
3732
}
3833
}
3934

40-
void Logger::debug(std::string str)
41-
{
35+
void Logger::debug(std::string str) {
4236
std::string log = std::format("[DEBUG]: {}", str);
4337
std::cout << str << std::endl;
4438
writeToFile(log);
4539
}
4640

47-
void Logger::info(std::string str)
48-
{
41+
void Logger::info(std::string str) {
4942
std::string log = std::format("[INFO]: {}", str);
5043
std::cout << str << std::endl;
5144
writeToFile(log);
5245
}
5346

54-
void Logger::warn(std::string str)
55-
{
47+
void Logger::warn(std::string str) {
5648
std::string log = std::format("[WARN]: {}", str);
5749
std::cout << str << std::endl;
5850
writeToFile(log);
5951
}
6052

61-
void Logger::error(std::string str)
62-
{
53+
void Logger::error(std::string str) {
6354
std::string log = std::format("[ERROR]: {}", str);
6455
std::cout << str << std::endl;
6556
writeToFile(log);
6657
}
6758

68-
void Logger::fatal(std::string str)
69-
{
59+
void Logger::fatal(std::string str) {
7060
std::string log = std::format("[FATAL]: {}", str);
7161
std::cout << str << std::endl;
7262
writeToFile(log);
7363
}
7464

75-
void Logger::trace(std::string str)
76-
{
65+
void Logger::trace(std::string str) {
7766
std::string log = std::format("[TRACE]: {}", str);
7867
std::cout << str << std::endl;
7968
writeToFile(log);

src/Utils/Logger/Logger.hpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,27 @@
11
#pragma once
2+
23
#include <string>
34

4-
class Logger
5-
{
5+
class Logger {
66
public:
77
static std::string file;
8-
static FILE* fp;
8+
static FILE *fp;
99
private:
10-
static void writeToFile(std::string);
10+
static void writeToFile(const std::string&);
1111

1212
public:
1313
static void initialize();
1414

1515
public:
1616
static void debug(std::string);
17+
1718
static void info(std::string);
19+
1820
static void warn(std::string);
21+
1922
static void error(std::string);
23+
2024
static void fatal(std::string);
25+
2126
static void trace(std::string);
2227
};

0 commit comments

Comments
 (0)