recording: Add logging header to simplify input recording logging

Appends [REC] to console logs when appropriate.  Auto appends new-line.  Sends similar logs to OSD if desired.
This commit is contained in:
Tyler Wilding 2020-09-24 22:50:56 -04:00 committed by refractionpcsx2
parent e44a6dcddb
commit b8f4fa0e87
4 changed files with 94 additions and 0 deletions

View File

@ -555,6 +555,7 @@ set(pcsx2RecordingHeaders
${rec_src}/InputRecordingFile.h
${rec_src}/NewRecordingFrame.h
${rec_src}/PadData.h
${rec_src}/Utilities/InputRecordingLogger.h
${rec_vp_src}/VirtualPad.h
${rec_vp_src}/VirtualPadData.h
${rec_vp_src}/VirtualPadResources.h

View File

@ -0,0 +1,86 @@
/* PCSX2 - PS2 Emulator for PCs
* Copyright (C) 2002-2020 PCSX2 Dev Team
*
* PCSX2 is free software: you can redistribute it and/or modify it under the terms
* of the GNU Lesser General Public License as published by the Free Software Found-
* ation, either version 3 of the License, or (at your option) any later version.
*
* PCSX2 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with PCSX2.
* If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include "App.h"
#include "ConsoleLogger.h"
#include "DebugTools/Debug.h"
#include "Utilities/Console.h"
#include <memory>
#include <string>
namespace inputRec
{
namespace
{
template <typename... Args>
static std::string fmtStr(const std::string& format, Args... args)
{
size_t size = snprintf(nullptr, 0, format.c_str(), args...) + 1;
if (size <= 0)
return std::string("");
std::unique_ptr<char[]> buf(new char[size]);
snprintf(buf.get(), size, format.c_str(), args...);
return std::string(buf.get(), buf.get() + size - 1);
}
} // namespace
template <typename... Args>
static void log(const std::string& format, Args... args)
{
std::string finalStr = fmtStr(format, std::forward<Args>(args)...);
if (finalStr.empty())
return;
recordingConLog("[REC]: " + finalStr + "\n");
// NOTE - Color is not currently used for OSD logs
if (GSosdLog)
GSosdLog(finalStr.c_str(), wxGetApp().GetProgramLog()->GetRGBA(ConsoleColors::Color_StrongMagenta));
}
template <typename... Args>
static void consoleLog(const std::string& format, Args... args)
{
std::string finalStr = fmtStr(format, std::forward<Args>(args)...);
if (finalStr.empty())
return;
recordingConLog(finalStr + "\n");
}
static void consoleMultiLog(std::vector<std::string> strs)
{
std::string finalStr;
for (std::string s : strs)
finalStr.append("[REC]: " + s + "\n");
recordingConLog(finalStr);
}
static void consoleMultiLog(std::vector<wxString> strs)
{
std::vector<std::string> stdStrs;
for (wxString s : strs)
stdStrs.push_back(std::string(s));
consoleMultiLog(stdStrs);
}
} // namespace inputRec

View File

@ -598,6 +598,7 @@
<ClInclude Include="..\..\Recording\VirtualPad\VirtualPad.h" />
<ClInclude Include="..\..\Recording\VirtualPad\VirtualPadData.h" />
<ClInclude Include="..\..\Recording\VirtualPad\VirtualPadResources.h" />
<ClInclude Include="..\..\Recording\Utilities\InputRecordingLogger.h" />
<ClInclude Include="..\..\Utilities\AsciiFile.h" />
<ClInclude Include="..\..\Elfheader.h" />
<ClInclude Include="..\..\CDVD\IsoFileFormats.h" />

View File

@ -163,6 +163,9 @@
<Filter Include="System\Ps2\SPU2">
<UniqueIdentifier>{bed493d6-96dc-4057-a1f2-31f88ec927d9}</UniqueIdentifier>
</Filter>
<Filter Include="Recording\Utilities">
<UniqueIdentifier>{85c5a0d2-6404-439f-8756-d908a1442b96}</UniqueIdentifier>
</Filter>
<Filter Include="Recording\VirtualPad\Images">
<UniqueIdentifier>{ad528458-08eb-49a2-aefa-3c2b86ab8896}</UniqueIdentifier>
</Filter>
@ -1518,6 +1521,9 @@
<ClInclude Include="..\..\SPU2\Windows\WinConfig.h">
<Filter>System\Ps2\SPU2</Filter>
</ClInclude>
<ClInclude Include="..\..\Recording\Utilities\InputRecordingLogger.h">
<Filter>Recording\Utilities</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="..\wxResources.rc">