mirror of
https://github.com/EQEmu/Server.git
synced 2025-12-20 13:21:28 +00:00
Cleanup Perl logging and streamline formatting, tie errors to main Quests logging category live output, add string utils
This commit is contained in:
parent
6e4d9a915d
commit
406b193206
@ -38,6 +38,35 @@ const std::string StringFormat(const char* format, ...);
|
|||||||
const std::string vStringFormat(const char* format, va_list args);
|
const std::string vStringFormat(const char* format, va_list args);
|
||||||
std::string implode(std::string glue, std::vector<std::string> src);
|
std::string implode(std::string glue, std::vector<std::string> src);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param s
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
static inline std::string <rim(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>
|
template <typename T>
|
||||||
std::string implode(const std::string &glue, const std::pair<char, char> &encapsulation, const std::vector<T> &src)
|
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
@ -137,10 +137,10 @@ void Embperl::DoInit() {
|
|||||||
try {
|
try {
|
||||||
init_eval_file();
|
init_eval_file();
|
||||||
}
|
}
|
||||||
catch(const char *err)
|
catch(std::string e)
|
||||||
{
|
{
|
||||||
//remember... lasterr() is no good if we crap out here, in construction
|
//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";
|
throw "failed to install eval_file hook";
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -177,9 +177,9 @@ void Embperl::DoInit() {
|
|||||||
perl_command = "main::eval_file('plugin', '" + Config->PluginPlFile + "');";
|
perl_command = "main::eval_file('plugin', '" + Config->PluginPlFile + "');";
|
||||||
eval_pv(perl_command.c_str(), FALSE);
|
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
|
try
|
||||||
{
|
{
|
||||||
@ -195,9 +195,9 @@ void Embperl::DoInit() {
|
|||||||
"}";
|
"}";
|
||||||
eval_pv(perl_command.c_str(),FALSE);
|
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
|
#endif //EMBPERL_PLUGIN
|
||||||
in_use = false;
|
in_use = false;
|
||||||
@ -237,7 +237,7 @@ void Embperl::init_eval_file(void)
|
|||||||
{
|
{
|
||||||
eval_pv(
|
eval_pv(
|
||||||
"our %Cache;"
|
"our %Cache;"
|
||||||
"no warnings;"
|
"no warnings 'all';"
|
||||||
"use Symbol qw(delete_package);"
|
"use Symbol qw(delete_package);"
|
||||||
"sub eval_file {"
|
"sub eval_file {"
|
||||||
"my($package, $filename) = @_;"
|
"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: ";
|
std::string errmsg = "Perl runtime error: ";
|
||||||
errmsg += SvPVX(ERRSV);
|
errmsg += SvPVX(ERRSV);
|
||||||
throw errmsg.c_str();
|
throw errmsg;
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret_value;
|
return ret_value;
|
||||||
|
|||||||
@ -100,15 +100,19 @@ XS(XS_EQEmuIO_PRINT)
|
|||||||
*std::remove(str, str + strlen(str), '\n') = '\0';
|
*std::remove(str, str + strlen(str), '\n') = '\0';
|
||||||
|
|
||||||
std::string log_string = str;
|
std::string log_string = str;
|
||||||
|
|
||||||
if (log_string.find("did not return a true") != std::string::npos)
|
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 i;
|
||||||
int pos = 0;
|
int pos = 0;
|
||||||
int len = 0;
|
int len = 0;
|
||||||
for(i = 0; *cur != '\0'; i++, cur++) {
|
for(i = 0; *cur != '\0'; i++, cur++) {
|
||||||
if(*cur == '\n') {
|
if(*cur == '\n') {
|
||||||
Log(Logs::General, Logs::Quests, str);
|
LogQuests(str);
|
||||||
len = 0;
|
len = 0;
|
||||||
pos = i+1;
|
pos = i+1;
|
||||||
} else {
|
} else {
|
||||||
@ -116,7 +120,7 @@ XS(XS_EQEmuIO_PRINT)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(len > 0) {
|
if(len > 0) {
|
||||||
Log(Logs::General, Logs::Quests, str);
|
LogQuests(str);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -84,7 +84,9 @@ public:
|
|||||||
err.insert(err.end(), errors_.begin(), errors_.end());
|
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);
|
errors_.push_back(error);
|
||||||
if(errors_.size() > 30) {
|
if(errors_.size() > 30) {
|
||||||
errors_.pop_front();
|
errors_.pop_front();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user