project64/Source/Project64-core/N64System/Recompiler/RecompilerCodeLog.cpp

73 lines
1.5 KiB
C++
Raw Normal View History

2016-01-27 09:11:59 +00:00
#include "stdafx.h"
#include "RecompilerCodeLog.h"
2016-01-27 09:11:59 +00:00
#include <Common/path.h>
#include <Common/Platform.h>
2016-01-27 09:11:59 +00:00
// vsprintf()
#include <stdio.h>
#include <stdarg.h>
2021-04-12 11:35:39 +00:00
static CLog * g_CPULogFile = nullptr;
2016-01-27 09:11:59 +00:00
void Recompiler_Log_Message(const char * strFormat, ...)
2016-01-27 09:11:59 +00:00
{
2016-04-19 10:38:14 +00:00
va_list args;
va_start(args, strFormat);
2018-02-13 06:38:33 +00:00
size_t nlen = _vscprintf(strFormat, args) + 1;
char * buffer = (char *)alloca((nlen + 3) * sizeof(char));
2021-04-12 11:35:39 +00:00
if (buffer != nullptr)
2016-04-19 10:38:14 +00:00
{
if (nlen > 0)
{
vsnprintf(buffer, nlen, strFormat, args);
buffer[nlen - 1] = '\0';
}
else
{
buffer[0] = '\0';
}
2016-04-19 10:38:14 +00:00
strcat(buffer, "\r\n");
g_CPULogFile->Log(buffer);
}
va_end(args);
2016-01-27 09:11:59 +00:00
}
void Start_Recompiler_Log (void)
2016-01-27 09:11:59 +00:00
{
2016-03-10 11:15:40 +00:00
CPath LogFileName(g_Settings->LoadStringVal(Directory_Log).c_str(), "CPUoutput.log");
2021-04-12 11:35:39 +00:00
if (g_CPULogFile != nullptr)
2016-04-19 10:38:14 +00:00
{
Stop_Recompiler_Log();
2016-04-19 10:38:14 +00:00
}
g_CPULogFile = new CLog();
if (g_CPULogFile)
2016-01-27 09:11:59 +00:00
{
2016-04-19 10:38:14 +00:00
if (g_CPULogFile->Open(LogFileName))
{
g_CPULogFile->SetMaxFileSize(300 * CLog::MB);
}
else
{
delete g_CPULogFile;
2021-04-12 11:35:39 +00:00
g_CPULogFile = nullptr;
2016-04-19 10:38:14 +00:00
}
2016-01-27 09:11:59 +00:00
}
}
void Stop_Recompiler_Log (void)
2016-01-27 09:11:59 +00:00
{
2021-04-12 11:35:39 +00:00
if (g_CPULogFile != nullptr)
2016-01-27 09:11:59 +00:00
{
2016-04-19 10:38:14 +00:00
delete g_CPULogFile;
2021-04-12 11:35:39 +00:00
g_CPULogFile = nullptr;
2016-01-27 09:11:59 +00:00
}
}
void Flush_Recompiler_Log(void)
{
2021-04-12 11:35:39 +00:00
if (g_CPULogFile != nullptr)
{
g_CPULogFile->Flush();
}
}