mirror of
https://github.com/BeamMP/BeamMP-Server.git
synced 2025-07-04 00:36:14 +00:00
start work on new logger
This commit is contained in:
parent
1bab3276e9
commit
d8c33c03ee
@ -15,6 +15,7 @@ public:
|
|||||||
void WriteRaw(const std::string& str);
|
void WriteRaw(const std::string& str);
|
||||||
void InitializeLuaConsole(TLuaEngine& Engine);
|
void InitializeLuaConsole(TLuaEngine& Engine);
|
||||||
void BackupOldLog();
|
void BackupOldLog();
|
||||||
|
void StartLoggingToFile();
|
||||||
Commandline& Internal() { return mCommandline; }
|
Commandline& Internal() { return mCommandline; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@ -37,4 +38,5 @@ private:
|
|||||||
bool mFirstTime { true };
|
bool mFirstTime { true };
|
||||||
std::string mStateId;
|
std::string mStateId;
|
||||||
const std::string mDefaultStateId = "BEAMMP_SERVER_CONSOLE";
|
const std::string mDefaultStateId = "BEAMMP_SERVER_CONSOLE";
|
||||||
|
std::ofstream mLogFileStream;
|
||||||
};
|
};
|
||||||
|
@ -97,6 +97,32 @@ void TConsole::BackupOldLog() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
enum EscState {
|
||||||
|
None,
|
||||||
|
Escape,
|
||||||
|
FeSeqStart,
|
||||||
|
FeSeqMid,
|
||||||
|
SeqEnd
|
||||||
|
};
|
||||||
|
|
||||||
|
void TConsole::StartLoggingToFile() {
|
||||||
|
mLogFileStream.open("Server.log");
|
||||||
|
Application::Console().Internal().on_write = [this](const std::string& ToWrite) {
|
||||||
|
// sanitize the string by removing all ANSI control codes (like color, etc)
|
||||||
|
std::string Sanitized;
|
||||||
|
Sanitized.reserve(ToWrite.size());
|
||||||
|
EscState state;
|
||||||
|
for (size_t i = 0; i < ToWrite.size(); ++i) {
|
||||||
|
if (i + 1 < ToWrite.size()
|
||||||
|
&& ToWrite[i] == 0x1b) { // starts ANSI escape sequence
|
||||||
|
if (ToWrite[i + 1] >= 0x40 || ToWrite[i + 1] <= 0x5F) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
mLogFileStream.write(ToWrite.c_str(), ToWrite.size());
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
void TConsole::ChangeToLuaConsole(const std::string& LuaStateId) {
|
void TConsole::ChangeToLuaConsole(const std::string& LuaStateId) {
|
||||||
if (!mIsLuaConsole) {
|
if (!mIsLuaConsole) {
|
||||||
if (!mLuaEngine) {
|
if (!mLuaEngine) {
|
||||||
|
@ -119,10 +119,8 @@ int BeamMPServerMain(MainArguments Arguments) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Application::SetSubsystemStatus("Main", Application::Status::Starting);
|
Application::SetSubsystemStatus("Main", Application::Status::Starting);
|
||||||
bool Success = Application::Console().Internal().enable_write_to_file("Server.log");
|
|
||||||
if (!Success) {
|
Application::Console().StartLoggingToFile();
|
||||||
beammp_error("unable to open file for writing: \"Server.log\"");
|
|
||||||
}
|
|
||||||
|
|
||||||
SetupSignalHandlers();
|
SetupSignalHandlers();
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user