Cleanup Perl logging and streamline formatting, tie errors to main Quests logging category live output, add string utils

This commit is contained in:
Akkadius 2020-01-01 19:04:11 -06:00
parent 6e4d9a915d
commit 406b193206
5 changed files with 618 additions and 432 deletions

View File

@ -38,6 +38,35 @@ const std::string StringFormat(const char* format, ...);
const std::string vStringFormat(const char* format, va_list args);
std::string implode(std::string glue, std::vector<std::string> src);
/**
* @param s
* @return
*/
static inline std::string &ltrim(std::string &s)
{
s.erase(s.begin(), std::find_if(s.begin(), s.end(), std::not1(std::ptr_fun<int, int>(std::isspace))));
return s;
}
/**
* @param s
* @return
*/
static inline std::string &rtrim(std::string &s)
{
s.erase(std::find_if(s.rbegin(), s.rend(), std::not1(std::ptr_fun<int, int>(std::isspace))).base(), s.end());
return s;
}
/**
* @param s
* @return
*/
static inline std::string &trim(std::string &s)
{
return ltrim(rtrim(s));
}
template <typename T>
std::string implode(const std::string &glue, const std::pair<char, char> &encapsulation, const std::vector<T> &src)
{

File diff suppressed because it is too large Load Diff

View File

@ -137,10 +137,10 @@ void Embperl::DoInit() {
try {
init_eval_file();
}
catch(const char *err)
catch(std::string e)
{
//remember... lasterr() is no good if we crap out here, in construction
LogQuests("perl error: [{}]", err);
LogQuests("Perl Error [{}]", e);
throw "failed to install eval_file hook";
}
@ -177,9 +177,9 @@ void Embperl::DoInit() {
perl_command = "main::eval_file('plugin', '" + Config->PluginPlFile + "');";
eval_pv(perl_command.c_str(), FALSE);
}
catch(const char *err)
catch(std::string e)
{
LogQuests("Warning - [{}]: [{}]", Config->PluginPlFile.c_str(), err);
LogQuests("Warning [{}]: [{}]", Config->PluginPlFile, e);
}
try
{
@ -195,9 +195,9 @@ void Embperl::DoInit() {
"}";
eval_pv(perl_command.c_str(),FALSE);
}
catch(const char *err)
catch(std::string e)
{
LogQuests("Perl warning: [{}]", err);
LogQuests("Warning [{}]", e);
}
#endif //EMBPERL_PLUGIN
in_use = false;
@ -237,7 +237,7 @@ void Embperl::init_eval_file(void)
{
eval_pv(
"our %Cache;"
"no warnings;"
"no warnings 'all';"
"use Symbol qw(delete_package);"
"sub eval_file {"
"my($package, $filename) = @_;"
@ -315,7 +315,7 @@ int Embperl::dosub(const char * subname, const std::vector<std::string> * args,
{
std::string errmsg = "Perl runtime error: ";
errmsg += SvPVX(ERRSV);
throw errmsg.c_str();
throw errmsg;
}
return ret_value;

View File

@ -100,15 +100,19 @@ XS(XS_EQEmuIO_PRINT)
*std::remove(str, str + strlen(str), '\n') = '\0';
std::string log_string = str;
if (log_string.find("did not return a true") != std::string::npos)
return;;
return;
if (log_string.find("is experimental") != std::string::npos)
return;
int i;
int pos = 0;
int len = 0;
for(i = 0; *cur != '\0'; i++, cur++) {
if(*cur == '\n') {
Log(Logs::General, Logs::Quests, str);
LogQuests(str);
len = 0;
pos = i+1;
} else {
@ -116,7 +120,7 @@ XS(XS_EQEmuIO_PRINT)
}
}
if(len > 0) {
Log(Logs::General, Logs::Quests, str);
LogQuests(str);
}
}

View File

@ -84,7 +84,9 @@ public:
err.insert(err.end(), errors_.begin(), errors_.end());
}
virtual void AddError(std::string error) {
virtual void AddError(std::string error) {
LogQuests(error);
errors_.push_back(error);
if(errors_.size() > 30) {
errors_.pop_front();