mirror of
https://github.com/SourMesen/Mesen2.git
synced 2025-04-02 10:21:44 -04:00
48 lines
No EOL
767 B
C++
48 lines
No EOL
767 B
C++
#pragma once
|
|
#include "pch.h"
|
|
|
|
class TraceLogFileSaver
|
|
{
|
|
private:
|
|
bool _enabled = false;
|
|
string _outputFilepath;
|
|
string _outputBuffer;
|
|
ofstream _outputFile;
|
|
|
|
public:
|
|
~TraceLogFileSaver()
|
|
{
|
|
StopLogging();
|
|
}
|
|
|
|
void StartLogging(string filename)
|
|
{
|
|
_outputBuffer.clear();
|
|
_outputFile.open(filename, ios::out | ios::binary);
|
|
_enabled = true;
|
|
}
|
|
|
|
void StopLogging()
|
|
{
|
|
if(_enabled) {
|
|
_enabled = false;
|
|
if(_outputFile) {
|
|
if(!_outputBuffer.empty()) {
|
|
_outputFile << _outputBuffer;
|
|
}
|
|
_outputFile.close();
|
|
}
|
|
}
|
|
}
|
|
|
|
__forceinline bool IsEnabled() { return _enabled; }
|
|
|
|
void Log(string& log)
|
|
{
|
|
_outputBuffer += log + '\n';
|
|
if(_outputBuffer.size() > 32768) {
|
|
_outputFile << _outputBuffer;
|
|
_outputBuffer.clear();
|
|
}
|
|
}
|
|
}; |