Script: Only log each string parameter warning message once
This commit is contained in:
@@ -90,3 +90,11 @@
|
|||||||
free(log->type);
|
free(log->type);
|
||||||
delete log;
|
delete log;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* static */ void ScriptLog::LogOnce(ScriptLog::ScriptLogType level, std::string &&message)
|
||||||
|
{
|
||||||
|
if (ScriptObject::IsNewUniqueLogMessage(message)) {
|
||||||
|
ScriptLog::Log(level, message.c_str());
|
||||||
|
ScriptObject::RegisterUniqueLogMessage(std::move(message));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@@ -75,6 +75,12 @@ public:
|
|||||||
*/
|
*/
|
||||||
static void FreeLogPointer();
|
static void FreeLogPointer();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Log this message once.
|
||||||
|
* @api -all
|
||||||
|
*/
|
||||||
|
static void LogOnce(ScriptLog::ScriptLogType level, std::string &&message);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/**
|
/**
|
||||||
* Internal command to log the message in a common way.
|
* Internal command to log the message in a common way.
|
||||||
|
@@ -411,3 +411,13 @@ void ScriptObject::InitializeRandomizers()
|
|||||||
ScriptObject::GetRandomizer(owner).SetSeed(random.Next());
|
ScriptObject::GetRandomizer(owner).SetSeed(random.Next());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* static */ bool ScriptObject::IsNewUniqueLogMessage(const std::string &msg)
|
||||||
|
{
|
||||||
|
return !GetStorage()->seen_unique_log_messages.contains(msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* static */ void ScriptObject::RegisterUniqueLogMessage(std::string &&msg)
|
||||||
|
{
|
||||||
|
GetStorage()->seen_unique_log_messages.emplace(std::move(msg));
|
||||||
|
}
|
||||||
|
@@ -304,6 +304,10 @@ protected:
|
|||||||
*/
|
*/
|
||||||
static char *GetString(StringID string);
|
static char *GetString(StringID string);
|
||||||
|
|
||||||
|
static bool IsNewUniqueLogMessage(const std::string &msg);
|
||||||
|
|
||||||
|
static void RegisterUniqueLogMessage(std::string &&msg);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/**
|
/**
|
||||||
* Store a new_vehicle_id per company.
|
* Store a new_vehicle_id per company.
|
||||||
|
@@ -170,12 +170,12 @@ const std::string ScriptText::GetEncodedText()
|
|||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScriptText::_TextParamError(const std::string &msg)
|
void ScriptText::_TextParamError(std::string msg)
|
||||||
{
|
{
|
||||||
if (this->GetActiveInstance()->IsTextParamMismatchAllowed()) {
|
if (this->GetActiveInstance()->IsTextParamMismatchAllowed()) {
|
||||||
ScriptLog::Error(msg.c_str());
|
ScriptLog::LogOnce(ScriptLog::LOG_ERROR, std::move(msg));
|
||||||
} else {
|
} else {
|
||||||
throw Script_FatalError(msg);
|
throw Script_FatalError(std::move(msg));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -135,7 +135,7 @@ private:
|
|||||||
std::variant<SQInteger, std::string, ScriptTextRef> param[SCRIPT_TEXT_MAX_PARAMETERS];
|
std::variant<SQInteger, std::string, ScriptTextRef> param[SCRIPT_TEXT_MAX_PARAMETERS];
|
||||||
int paramc;
|
int paramc;
|
||||||
|
|
||||||
void _TextParamError(const std::string &msg);
|
void _TextParamError(std::string msg);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Internal function for recursive calling this function over multiple
|
* Internal function for recursive calling this function over multiple
|
||||||
|
@@ -22,6 +22,9 @@ public:
|
|||||||
Script_FatalError(const std::string &msg) :
|
Script_FatalError(const std::string &msg) :
|
||||||
msg(msg)
|
msg(msg)
|
||||||
{}
|
{}
|
||||||
|
Script_FatalError(std::string &&msg) :
|
||||||
|
msg(std::move(msg))
|
||||||
|
{}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The error message associated with the fatal error.
|
* The error message associated with the fatal error.
|
||||||
|
@@ -16,6 +16,7 @@
|
|||||||
#include "../group.h"
|
#include "../group.h"
|
||||||
#include "../goal_type.h"
|
#include "../goal_type.h"
|
||||||
#include "../story_type.h"
|
#include "../story_type.h"
|
||||||
|
#include "../3rdparty/robin_hood/robin_hood.h"
|
||||||
|
|
||||||
#include "table/strings.h"
|
#include "table/strings.h"
|
||||||
#include <vector>
|
#include <vector>
|
||||||
@@ -66,6 +67,8 @@ private:
|
|||||||
void *event_data; ///< Pointer to the event data storage.
|
void *event_data; ///< Pointer to the event data storage.
|
||||||
void *log_data; ///< Pointer to the log data storage.
|
void *log_data; ///< Pointer to the log data storage.
|
||||||
|
|
||||||
|
robin_hood::unordered_node_set<std::string> seen_unique_log_messages; ///< Messages which have already been logged once and don't need to be logged again
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ScriptStorage() :
|
ScriptStorage() :
|
||||||
mode (nullptr),
|
mode (nullptr),
|
||||||
|
Reference in New Issue
Block a user