Add Logging utility for logging Http and Output calls
This commit is contained in:
parent
8f3192298d
commit
f432851d98
|
|
@ -0,0 +1,42 @@
|
|||
#include "pch.h"
|
||||
#include "Logger.h"
|
||||
|
||||
#pragma warning(disable : 4996)
|
||||
|
||||
HANDLE Logger::handle;
|
||||
std::ofstream Logger::outputLog;
|
||||
std::ofstream Logger::httpLog;
|
||||
|
||||
void Logger::Initialize(const std::string jobId)
|
||||
{
|
||||
AllocConsole();
|
||||
freopen_s((FILE**)stdout, "CONOUT$", "w", stdout);
|
||||
Logger::handle = CreateFileA("CONOUT$", GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
|
||||
SetStdHandle(STD_OUTPUT_HANDLE, Logger::handle);
|
||||
|
||||
Logger::outputLog = std::ofstream(jobId + std::string("-Output.txt"));
|
||||
Logger::httpLog = std::ofstream(jobId + std::string("-Http.txt"));
|
||||
}
|
||||
|
||||
void Logger::Log(LogType type, const std::string message)
|
||||
{
|
||||
if (!handle) return;
|
||||
|
||||
switch (type)
|
||||
{
|
||||
case LogType::Output:
|
||||
outputLog << "[" << Logger::UtcTime() << "] " << message.c_str() << std::endl;
|
||||
break;
|
||||
case LogType::Http:
|
||||
httpLog << "[" << Logger::UtcTime() << "] " << message.c_str() << std::endl;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
std::string Logger::UtcTime()
|
||||
{
|
||||
std::stringstream time;
|
||||
std::time_t now = std::time(NULL);
|
||||
time << std::put_time(std::localtime(&now), "%F %T");
|
||||
return time.str();
|
||||
}
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
#pragma once
|
||||
|
||||
#include "pch.h"
|
||||
|
||||
enum class LogType { Output, Http };
|
||||
|
||||
class Logger
|
||||
{
|
||||
private:
|
||||
static std::ofstream outputLog;
|
||||
static std::ofstream httpLog;
|
||||
public:
|
||||
static HANDLE handle;
|
||||
static void Initialize(const std::string jobId);
|
||||
static void Log(LogType type, const std::string message);
|
||||
static std::string UtcTime();
|
||||
};
|
||||
|
|
@ -158,6 +158,7 @@
|
|||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="Config.h" />
|
||||
<ClInclude Include="Logger.h" />
|
||||
<ClInclude Include="LUrlParser.h" />
|
||||
<ClInclude Include="Patches.h" />
|
||||
<ClInclude Include="pch.h" />
|
||||
|
|
@ -166,6 +167,7 @@
|
|||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="dllmain.cpp" />
|
||||
<ClCompile Include="Logger.cpp" />
|
||||
<ClCompile Include="LUrlParser.cpp">
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">NotUsing</PrecompiledHeader>
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">NotUsing</PrecompiledHeader>
|
||||
|
|
|
|||
|
|
@ -33,6 +33,9 @@
|
|||
<ClInclude Include="LUrlParser.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Logger.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="dllmain.cpp">
|
||||
|
|
@ -50,5 +53,8 @@
|
|||
<ClCompile Include="LUrlParser.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Logger.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
|
|
@ -1,12 +1,8 @@
|
|||
#include "pch.h"
|
||||
#include "Config.h"
|
||||
#include "RobloxMFCHooks.h"
|
||||
#include "Logger.h"
|
||||
#include "Config.h"
|
||||
#include "LUrlParser.h"
|
||||
|
||||
static HANDLE handle;
|
||||
static std::ofstream jobOutputLog;
|
||||
static std::ofstream jobHttpLog;
|
||||
|
||||
static bool hasAuthUrlArg = false;
|
||||
static bool hasAuthTicketArg = false;
|
||||
static bool hasJoinArg = false;
|
||||
|
|
@ -91,13 +87,7 @@ void __fastcall CRobloxCommandLineInfo__ParseParam_hook(CRobloxCommandLineInfo*
|
|||
if (hasJobId && jobId.empty())
|
||||
{
|
||||
jobId = std::string(pszParam);
|
||||
jobOutputLog = std::ofstream(jobId + std::string("-Output.txt"));
|
||||
jobHttpLog = std::ofstream(jobId + std::string("-Http.txt"));
|
||||
|
||||
AllocConsole();
|
||||
freopen_s((FILE**)stdout, "CONOUT$", "w", stdout);
|
||||
handle = CreateFileA("CONOUT$", GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
|
||||
SetStdHandle(STD_OUTPUT_HANDLE, handle);
|
||||
Logger::Initialize(jobId);
|
||||
|
||||
CCommandLineInfo__ParseLast(_this, bLast);
|
||||
return;
|
||||
|
|
@ -174,7 +164,9 @@ BOOL __fastcall Http__trustCheck_hook(const char* url)
|
|||
if (!parsedUrl.isValid())
|
||||
return false;
|
||||
|
||||
jobHttpLog << url << std::endl;
|
||||
#ifdef ARBITERBUILD
|
||||
Logger::Log(LogType::Http, url);
|
||||
#endif
|
||||
|
||||
if (std::string("about:blank") == url)
|
||||
return true;
|
||||
|
|
@ -196,24 +188,24 @@ void __fastcall StandardOut__print_hook(void* _this, void*, int type, const std:
|
|||
switch (type)
|
||||
{
|
||||
case 1: // RBX::MESSAGE_OUTPUT:
|
||||
jobOutputLog << "[RBX::MESSAGE_OUTPUT] " << message.c_str() << std::endl;
|
||||
SetConsoleTextAttribute(handle, FOREGROUND_BLUE | FOREGROUND_INTENSITY);
|
||||
Logger::Log(LogType::Output, std::string("[MESSAGE_OUTPUT] ") + message);
|
||||
SetConsoleTextAttribute(Logger::handle, FOREGROUND_BLUE | FOREGROUND_INTENSITY);
|
||||
break;
|
||||
case 0: // RBX::MESSAGE_INFO:
|
||||
jobOutputLog << "[RBX::MESSAGE_INFO] " << message.c_str() << std::endl;
|
||||
SetConsoleTextAttribute(handle, FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);
|
||||
Logger::Log(LogType::Output, std::string("[MESSAGE_INFO] ") + message);
|
||||
SetConsoleTextAttribute(Logger::handle, FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);
|
||||
break;
|
||||
case 2: // RBX::MESSAGE_WARNING:
|
||||
jobOutputLog << "[RBX::MESSAGE_WARNING] " << message.c_str() << std::endl;
|
||||
SetConsoleTextAttribute(handle, FOREGROUND_RED | FOREGROUND_GREEN);
|
||||
Logger::Log(LogType::Output, std::string("[MESSAGE_WARNING] ") + message);
|
||||
SetConsoleTextAttribute(Logger::handle, FOREGROUND_RED | FOREGROUND_GREEN);
|
||||
break;
|
||||
case 3: // RBX::MESSAGE_ERROR:
|
||||
jobOutputLog << "[RBX::MESSAGE_ERROR] " << message.c_str() << std::endl;
|
||||
SetConsoleTextAttribute(handle, FOREGROUND_RED | FOREGROUND_INTENSITY);
|
||||
Logger::Log(LogType::Output, std::string("[MESSAGE_ERROR] ") + message);
|
||||
SetConsoleTextAttribute(Logger::handle, FOREGROUND_RED | FOREGROUND_INTENSITY);
|
||||
break;
|
||||
}
|
||||
printf("%s\n", message.c_str());
|
||||
SetConsoleTextAttribute(handle, FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);
|
||||
SetConsoleTextAttribute(Logger::handle, FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);
|
||||
|
||||
StandardOut__print(_this, type, message);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,7 +2,9 @@
|
|||
|
||||
#include <Windows.h>
|
||||
#include <iostream>
|
||||
#include <iomanip>
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <stdexcept>
|
||||
Loading…
Reference in New Issue