diff --git a/core/models/LogEvent.cpp b/core/models/LogEvent.cpp index fab4c2b19d..42d5f23283 100644 --- a/core/models/LogEvent.cpp +++ b/core/models/LogEvent.cpp @@ -78,6 +78,10 @@ void LogEvent::DelContent(StringView key) { } } +StringView LogEvent::GetLevel() const { + return mLevel; +} + void LogEvent::SetLevel(const std::string& level) { SetLevelNoCopy(GetSourceBuffer()->CopyString(level)); } diff --git a/core/models/LogEvent.h b/core/models/LogEvent.h index 0cb8f8a7a8..4360e9be00 100644 --- a/core/models/LogEvent.h +++ b/core/models/LogEvent.h @@ -87,6 +87,7 @@ class LogEvent : public PipelineEvent { } std::pair GetPosition() const { return {mFileOffset, mRawSize}; } + StringView GetLevel() const; void SetLevel(const std::string& level); void SetLevelNoCopy(const StringBuffer& level); void SetLevelNoCopy(StringView level); diff --git a/core/unittest/models/LogEventUnittest.cpp b/core/unittest/models/LogEventUnittest.cpp index 673c11878b..29d30424e8 100644 --- a/core/unittest/models/LogEventUnittest.cpp +++ b/core/unittest/models/LogEventUnittest.cpp @@ -30,6 +30,7 @@ class LogEventUnittest : public ::testing::Test { void TestMeta(); void TestSize(); void TestFromJsonToJson(); + void TestLevel(); protected: void SetUp() override { @@ -202,6 +203,11 @@ void LogEventUnittest::TestFromJsonToJson() { APSARA_TEST_STREQ(CompactJson(inJson).c_str(), CompactJson(outJson).c_str()); } +void LogEventUnittest::TestLevel() { + mLogEvent->SetLevel("level"); + APSARA_TEST_EQUAL("level", mLogEvent->GetLevel().to_string()); +} + UNIT_TEST_CASE(LogEventUnittest, TestTimestampOp) UNIT_TEST_CASE(LogEventUnittest, TestSetContent) UNIT_TEST_CASE(LogEventUnittest, TestDelContent)