mirror of
https://github.com/badaix/snapcast.git
synced 2025-05-19 03:56:14 +02:00
Scan logline with a regex
This commit is contained in:
parent
1fb80e81c4
commit
d93773f46c
1 changed files with 21 additions and 27 deletions
|
@ -119,33 +119,28 @@ void LibrespotStream::onStderrMsg(const std::string& line)
|
||||||
|
|
||||||
// Parse log level, source and message from the log line
|
// Parse log level, source and message from the log line
|
||||||
// Format: [2021-05-09T08:31:08Z DEBUG librespot_playback::player] new Player[0]
|
// Format: [2021-05-09T08:31:08Z DEBUG librespot_playback::player] new Player[0]
|
||||||
std::string level;
|
|
||||||
std::string source;
|
|
||||||
std::string message;
|
|
||||||
level = utils::string::split_left(line, ' ', source);
|
|
||||||
level = utils::string::split_left(source, ' ', source);
|
|
||||||
source = utils::string::split_left(source, ']', message);
|
|
||||||
utils::string::trim(level);
|
|
||||||
utils::string::trim(source);
|
|
||||||
utils::string::trim(message);
|
|
||||||
|
|
||||||
AixLog::Severity severity = AixLog::Severity::info;
|
smatch m;
|
||||||
bool parsed = true;
|
static regex re_log_line(R"(\[(\S+)(\s+)(\bTRACE\b|\bDEBUG\b|\bINFO\b|\bWARN\b|\bERROR\b)(\s+)(.*)\] (.*))");
|
||||||
if (level == "TRACE")
|
if (regex_search(line, m, re_log_line) && (m.size() == 7))
|
||||||
severity = AixLog::Severity::trace;
|
{
|
||||||
else if (level == "DEBUG")
|
const std::string& level = m[3];
|
||||||
severity = AixLog::Severity::debug;
|
const std::string& source = m[5];
|
||||||
else if (level == "INFO")
|
const std::string& message = m[6];
|
||||||
severity = AixLog::Severity::info;
|
AixLog::Severity severity = AixLog::Severity::info;
|
||||||
else if (level == "WARN")
|
if (level == "TRACE")
|
||||||
severity = AixLog::Severity::warning;
|
severity = AixLog::Severity::trace;
|
||||||
else if (level == "ERROR")
|
else if (level == "DEBUG")
|
||||||
severity = AixLog::Severity::error;
|
severity = AixLog::Severity::debug;
|
||||||
else
|
else if (level == "INFO")
|
||||||
parsed = false;
|
severity = AixLog::Severity::info;
|
||||||
|
else if (level == "WARN")
|
||||||
|
severity = AixLog::Severity::warning;
|
||||||
|
else if (level == "ERROR")
|
||||||
|
severity = AixLog::Severity::error;
|
||||||
|
|
||||||
if (parsed)
|
|
||||||
LOG(severity, source) << message << "\n";
|
LOG(severity, source) << message << "\n";
|
||||||
|
}
|
||||||
else
|
else
|
||||||
LOG(INFO, LOG_TAG) << "(" << getName() << ") " << line << "\n";
|
LOG(INFO, LOG_TAG) << "(" << getName() << ") " << line << "\n";
|
||||||
|
|
||||||
|
@ -155,7 +150,6 @@ void LibrespotStream::onStderrMsg(const std::string& line)
|
||||||
// [2021-06-04T07:20:47Z INFO librespot_playback::player] <Tunnel> (310573 ms) loaded
|
// [2021-06-04T07:20:47Z INFO librespot_playback::player] <Tunnel> (310573 ms) loaded
|
||||||
// info!("Track \"{}\" loaded", track.name);
|
// info!("Track \"{}\" loaded", track.name);
|
||||||
// std::cerr << line << "\n";
|
// std::cerr << line << "\n";
|
||||||
smatch m;
|
|
||||||
static regex re_patched("metadata:(.*)");
|
static regex re_patched("metadata:(.*)");
|
||||||
static regex re_track_loaded(R"( <(.*)> \((.*) ms\) loaded)");
|
static regex re_track_loaded(R"( <(.*)> \((.*) ms\) loaded)");
|
||||||
// Parse the patched version
|
// Parse the patched version
|
||||||
|
@ -176,10 +170,10 @@ void LibrespotStream::onStderrMsg(const std::string& line)
|
||||||
meta.title = string(m[1]);
|
meta.title = string(m[1]);
|
||||||
meta.duration = cpt::stod(m[2]) / 1000.;
|
meta.duration = cpt::stod(m[2]) / 1000.;
|
||||||
setMeta(meta);
|
setMeta(meta);
|
||||||
// Properties props;
|
Properties props;
|
||||||
// props.can_seek = true;
|
// props.can_seek = true;
|
||||||
// props.can_control = true;
|
// props.can_control = true;
|
||||||
// setProperties(props);
|
setProperties(props);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue