2023-03-06 15:40:07 -05:00
|
|
|
#include <std_include.hpp>
|
|
|
|
#include "logger.hpp"
|
2023-09-06 08:08:38 -04:00
|
|
|
#include "game_console.hpp"
|
2023-03-06 15:40:07 -05:00
|
|
|
#include "loader/component_loader.hpp"
|
2023-09-06 08:08:38 -04:00
|
|
|
|
2023-11-10 16:52:20 -05:00
|
|
|
#include <utilities/nt.hpp>
|
2023-03-06 15:40:07 -05:00
|
|
|
|
|
|
|
#define OUTPUT_DEBUG_API
|
2023-09-06 08:08:38 -04:00
|
|
|
#define OUTPUT_GAME_CONSOLE
|
2023-03-06 15:40:07 -05:00
|
|
|
|
|
|
|
namespace logger
|
|
|
|
{
|
2023-05-11 16:50:11 -04:00
|
|
|
const char* LogTypeNames[] =
|
2023-03-06 15:40:07 -05:00
|
|
|
{
|
2023-05-11 16:50:11 -04:00
|
|
|
"DEBUG",
|
|
|
|
"INFO",
|
|
|
|
"WARN",
|
|
|
|
"ERROR"
|
|
|
|
};
|
2023-03-06 15:40:07 -05:00
|
|
|
|
|
|
|
void write(const int type, std::string str)
|
|
|
|
{
|
2023-05-11 16:50:11 -04:00
|
|
|
#ifndef _DEBUG
|
|
|
|
if (type == LOG_TYPE_DEBUG) return;
|
|
|
|
#endif // _DEBUG
|
|
|
|
|
2023-09-06 08:08:38 -04:00
|
|
|
std::stringstream ss;
|
|
|
|
ss << "[ " << LogTypeNames[type] << " ] " << str << std::endl;
|
|
|
|
|
|
|
|
std::string text = ss.str();
|
|
|
|
|
|
|
|
#ifdef OUTPUT_GAME_CONSOLE
|
|
|
|
game_console::print(text);
|
|
|
|
#endif // OUTPUT_GAME_CONSOLE
|
|
|
|
|
2023-03-06 15:40:07 -05:00
|
|
|
#ifdef OUTPUT_DEBUG_API
|
2023-09-06 08:08:38 -04:00
|
|
|
OutputDebugStringA(text.c_str());
|
2023-03-06 15:40:07 -05:00
|
|
|
#endif // OUTPUT_DEBUG_API
|
|
|
|
|
2023-09-06 08:08:38 -04:00
|
|
|
std::ofstream fs;
|
|
|
|
fs.open("project-bo4.log", std::ios_base::app);
|
2023-03-06 15:40:07 -05:00
|
|
|
|
|
|
|
time_t now = time(0);
|
|
|
|
std::tm* t = std::localtime(&now);
|
2023-09-06 08:08:38 -04:00
|
|
|
fs << "" << std::put_time(t, "%Y-%m-%d %H:%M:%S") << "\t" << text;
|
2023-03-06 15:40:07 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void write(const int type, const char* fmt, ...)
|
|
|
|
{
|
|
|
|
char va_buffer[0x800] = { 0 };
|
|
|
|
|
|
|
|
va_list ap;
|
|
|
|
va_start(ap, fmt);
|
|
|
|
vsprintf_s(va_buffer, fmt, ap);
|
|
|
|
va_end(ap);
|
|
|
|
|
|
|
|
const auto formatted = std::string(va_buffer);
|
|
|
|
write(type, formatted);
|
|
|
|
}
|
|
|
|
|
|
|
|
class component final : public component_interface
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
void pre_start() override
|
|
|
|
{
|
2023-05-11 16:50:11 -04:00
|
|
|
#ifdef REMOVE_PREVIOUS_LOG
|
2023-11-10 16:52:20 -05:00
|
|
|
utilities::io::remove_file("project-bo4.log");
|
2023-05-11 16:50:11 -04:00
|
|
|
#endif // REMOVE_PREVIOUS_LOG
|
|
|
|
|
2023-09-06 08:08:38 -04:00
|
|
|
write(LOG_TYPE_INFO, "=======================================================================================================");
|
2023-11-10 16:52:20 -05:00
|
|
|
write(LOG_TYPE_INFO, " Project-BO4 Initializing ... %s[0x%llX]", utilities::nt::library{}.get_name().c_str(), utilities::nt::library{}.get_ptr());
|
2023-09-06 08:08:38 -04:00
|
|
|
write(LOG_TYPE_INFO, "=======================================================================================================");
|
2023-03-06 15:40:07 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void post_unpack() override
|
|
|
|
{
|
|
|
|
/* PLACE_HOLDER */
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
2023-05-11 16:50:11 -04:00
|
|
|
REGISTER_COMPONENT(logger::component)
|