Use simple string parsing instead of regex

fixes #1026
This commit is contained in:
badaix 2022-06-30 19:19:55 +02:00
parent 4d9a2b7ea1
commit 4907fb42af
2 changed files with 141 additions and 19 deletions

View file

@ -37,6 +37,7 @@ namespace streamreader
static constexpr auto LOG_TAG = "LibrespotStream";
// https://commons.wikimedia.org/wiki/File:Spotify_logo_without_text.svg
static constexpr auto SPOTIFY_LOGO = "PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiIHN0YW5kYWxvbmU9Im5vIj8+Cjxz"
"dmcgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiBoZWlnaHQ9IjE2OHB4IiB3aWR0"
"aD0iMTY4cHgiIHZlcnNpb249IjEuMSIgdmlld0JveD0iMCAwIDE2OCAxNjgiPgogPHBhdGggZmls"
@ -146,27 +147,29 @@ void LibrespotStream::onStderrMsg(const std::string& line)
// Parse log level, source and message from the log line
// Format: [2021-05-09T08:31:08Z DEBUG librespot_playback::player] new Player[0]
smatch m;
static regex re_log_line(R"(\[(\S+)(\s+)(\bTRACE\b|\bDEBUG\b|\bINFO\b|\bWARN\b|\bERROR\b)(\s+)(.*)\] (.*))");
if (regex_search(line, m, re_log_line) && (m.size() == 7))
{
const std::string& level = m[3];
const std::string& source = m[5];
const std::string& message = m[6];
AixLog::Severity severity = AixLog::Severity::info;
if (level == "TRACE")
severity = AixLog::Severity::trace;
else if (level == "DEBUG")
severity = AixLog::Severity::debug;
else if (level == "INFO")
severity = AixLog::Severity::info;
else if (level == "WARN")
severity = AixLog::Severity::warning;
else if (level == "ERROR")
severity = AixLog::Severity::error;
std::string message = line;
utils::string::split_left(message, ' ', message);
std::string level = utils::string::trim_copy(utils::string::split_left(message, ' ', message));
std::string source = utils::string::trim_copy(utils::string::split_left(message, ']', message));
utils::string::trim(message);
bool parsed = true;
AixLog::Severity severity = AixLog::Severity::info;
if (level == "TRACE")
severity = AixLog::Severity::trace;
else if (level == "DEBUG")
severity = AixLog::Severity::debug;
else if (level == "INFO")
severity = AixLog::Severity::info;
else if (level == "WARN")
severity = AixLog::Severity::warning;
else if (level == "ERROR")
severity = AixLog::Severity::error;
else
parsed = false;
if (parsed)
LOG(severity, source) << message << "\n";
}
else
LOG(INFO, LOG_TAG) << "(" << getName() << ") " << line << "\n";
@ -176,6 +179,7 @@ void LibrespotStream::onStderrMsg(const std::string& line)
// [2021-06-04T07:20:47Z INFO librespot_playback::player] <Tunnel> (310573 ms) loaded
// info!("Track \"{}\" loaded", track.name);
// std::cerr << line << "\n";
smatch m;
static regex re_patched("metadata:(.*)");
static regex re_track_loaded(R"( <(.*)> \((.*) ms\) loaded)");
// Parse the patched version