Skip to content

Commit

Permalink
remove MESSAGE= prefix from messages
Browse files Browse the repository at this point in the history
  • Loading branch information
bastidest committed Nov 5, 2023
1 parent 3314ced commit f7db158
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions src/SdJournal.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,22 @@ class SdJournal {

bool next() { return sd_journal_next(handle.get()) > 0; }

SdLine getLine() {
std::string_view getFieldString(std::string_view sFieldName) {
const void *ptr = nullptr;
size_t uMessageLength{};
sd_journal_get_data(handle.get(), "MESSAGE", reinterpret_cast<const void **>(&ptr), &uMessageLength);
std::string sMessage{static_cast<const char *>(ptr)};
sd_journal_get_data(handle.get(), "MESSAGE_ID", reinterpret_cast<const void **>(&ptr), &uMessageLength);
std::string sRealtimeTimestamp{static_cast<const char *>(ptr)};
return SdLine{sMessage, sRealtimeTimestamp};
sd_journal_get_data(handle.get(), sFieldName.data(), reinterpret_cast<const void **>(&ptr), &uMessageLength);
std::string_view ret{static_cast<const char *>(ptr), uMessageLength};

if(ret.size() >= sFieldName.size() + 1) {
return ret.substr(sFieldName.size() + 1);
}

#pragma clang diagnostic push
#pragma ide diagnostic ignored "LocalValueEscapesScope"
return ret;
#pragma clang diagnostic pop
}

SdLine getLine() { return SdLine{std::string{getFieldString("MESSAGE")}, std::string{getFieldString("MESSAGE_ID")}}; }
};
} // namespace jess

0 comments on commit f7db158

Please sign in to comment.