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
|
|
|
|
|
|
|
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",
|
2024-07-28 04:56:23 -04:00
|
|
|
"ERROR",
|
|
|
|
""
|
2023-05-11 16:50:11 -04:00
|
|
|
};
|
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
|
|
|
|
|
2024-07-28 04:56:23 -04:00
|
|
|
game_console::print(str);
|
|
|
|
if (type == type::LOG_TYPE_CONSOLE) return;
|
|
|
|
|
2023-09-06 08:08:38 -04:00
|
|
|
std::stringstream ss;
|
|
|
|
ss << "[ " << LogTypeNames[type] << " ] " << str << std::endl;
|
|
|
|
|
|
|
|
std::string text = ss.str();
|
|
|
|
|
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
|
|
|
|
|
2024-05-23 02:48:21 -04:00
|
|
|
printf(text.c_str()); //print debug messages to new console
|
2023-09-06 08:08:38 -04:00
|
|
|
std::ofstream fs;
|
2024-05-16 17:35:57 -04:00
|
|
|
fs.open("t8-mod.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
|
2024-05-16 17:35:57 -04:00
|
|
|
utilities::io::remove_file("t8-mod.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, "=======================================================================================================");
|
2024-05-16 17:35:57 -04:00
|
|
|
write(LOG_TYPE_INFO, " T8-Mod 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
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
2023-05-11 16:50:11 -04:00
|
|
|
REGISTER_COMPONENT(logger::component)
|