You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by bn...@apache.org on 2024/01/30 16:25:37 UTC

(trafficserver-libswoc) branch errata-note-severity created (now 2c24e22)

This is an automated email from the ASF dual-hosted git repository.

bneradt pushed a change to branch errata-note-severity
in repository https://gitbox.apache.org/repos/asf/trafficserver-libswoc.git


      at 2c24e22  Tweaks.

This branch includes the following new commits:

     new e541322  Errata - fix issues with stream output different from BWF output.
     new 2c24e22  Tweaks.

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



(trafficserver-libswoc) 02/02: Tweaks.

Posted by bn...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

bneradt pushed a commit to branch errata-note-severity
in repository https://gitbox.apache.org/repos/asf/trafficserver-libswoc.git

commit 2c24e22223576540b7da5aebd231976c0aa0da67
Author: Alan M. Carroll <am...@apache.org>
AuthorDate: Mon Jan 10 15:52:31 2022 -0600

    Tweaks.
---
 code/include/swoc/Errata.h | 2 --
 code/src/Errata.cc         | 7 ++++---
 2 files changed, 4 insertions(+), 5 deletions(-)

diff --git a/code/include/swoc/Errata.h b/code/include/swoc/Errata.h
index a1874e1..1076096 100644
--- a/code/include/swoc/Errata.h
+++ b/code/include/swoc/Errata.h
@@ -185,8 +185,6 @@ protected:
 
     Severity _severity{Errata::DEFAULT_SEVERITY}; ///< Severity.
     code_type _code{Errata::DEFAULT_CODE};        ///< Message code / ID
-    unsigned _level{0};                           ///< Nesting level.
-    std::atomic<int> _ref_count{0};               ///< Reference count.
     Container _notes;                             ///< The message stack.
     swoc::MemArena _arena;                        ///< Annotation text storage.
   };
diff --git a/code/src/Errata.cc b/code/src/Errata.cc
index 2b7b0da..b93e328 100644
--- a/code/src/Errata.cc
+++ b/code/src/Errata.cc
@@ -95,7 +95,7 @@ Errata::note_s(std::optional<Severity> severity, std::string_view text) {
 Errata&
 Errata::note_localized(std::string_view const& text, std::optional<Severity> severity) {
   auto d = this->data();
-  Annotation *n = d->_arena.make<Annotation>(text, severity, d->_level);
+  Annotation *n = d->_arena.make<Annotation>(text, severity);
   d->_notes.append(n);
   return *this;
 }
@@ -107,8 +107,9 @@ Errata::alloc(size_t n) {
 
 Errata&
 Errata::note(const self_type& that) {
-  for (auto const& m : that) {
-    this->note(m._text);
+  auto d = this->data();
+  for (auto const& annotation : that) {
+    d->_notes.append(d->_arena.make<Annotation>(d->localize(annotation._text), annotation._severity, annotation._level + 1));
   }
   return *this;
 }


(trafficserver-libswoc) 01/02: Errata - fix issues with stream output different from BWF output.

Posted by bn...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

bneradt pushed a commit to branch errata-note-severity
in repository https://gitbox.apache.org/repos/asf/trafficserver-libswoc.git

commit e541322e4a48253dff31f6a97d39020241728ef3
Author: Alan M. Carroll <am...@apache.org>
AuthorDate: Mon Jan 10 14:05:00 2022 -0600

    Errata - fix issues with stream output different from BWF output.
---
 code/src/Errata.cc        | 38 ++++++++++----------------------------
 unit_tests/test_Errata.cc | 31 ++++++++++++++++++++++---------
 2 files changed, 32 insertions(+), 37 deletions(-)

diff --git a/code/src/Errata.cc b/code/src/Errata.cc
index 81bf463..2b7b0da 100644
--- a/code/src/Errata.cc
+++ b/code/src/Errata.cc
@@ -126,32 +126,6 @@ Errata::register_sink(Sink::Handle const& s) {
   Sink_List.push_back(s);
 }
 
-std::ostream&
-Errata::write(std::ostream& out) const {
-  string_view lead;
-
-  auto level = this->severity();
-  if (level < Errata::SEVERITY_NAMES.size()) {
-    out << Errata::SEVERITY_NAMES[level];
-  } else {
-    out << unsigned(level._raw);
-  }
-
-  out << ": ";
-
-  if (this->code()) {
-    out << this->code().message() << " [" << this->code().value() << "] - ";
-  }
-
-  for (auto& m : *this) {
-    out << lead << m._text << std::endl;
-    if (0 == lead.size()) {
-      lead = "  "_sv;
-    }
-  }
-  return out;
-}
-
 BufferWriter&
 bwformat(BufferWriter& bw, bwf::Spec const& spec, Errata::Severity level) {
   if (level < Errata::SEVERITY_NAMES.size()) {
@@ -165,7 +139,7 @@ bwformat(BufferWriter& bw, bwf::Spec const& spec, Errata::Severity level) {
 BufferWriter&
 bwformat(BufferWriter& bw, bwf::Spec const&, Errata const& errata) {
 
-  bw.print("{} ", errata.severity());
+  bw.print("{}: ", errata.severity());
 
   if (errata.code()) {
     bw.print("[{0:s} {0:d}] ", errata.code());
@@ -175,13 +149,21 @@ bwformat(BufferWriter& bw, bwf::Spec const&, Errata const& errata) {
     if (note.text()) {
       bw.print("{}{}{}\n"
                , swoc::bwf::Pattern{int(note.level()), "  "}
-               , swoc::bwf::If(note.has_severity(), "{} ", note.severity())
+               , swoc::bwf::If(note.has_severity(), "{}: ", note.severity())
                , note.text());
     }
   }
   return bw;
 }
 
+std::ostream&
+Errata::write(std::ostream& out) const {
+  std::string tmp;
+  tmp.reserve(1024);
+  bwprint(tmp, "{}", *this);
+  return out << tmp;
+}
+
 std::ostream&
 operator<<(std::ostream& os, Errata const& err) {
   return err.write(os);
diff --git a/unit_tests/test_Errata.cc b/unit_tests/test_Errata.cc
index 98de648..d23a148 100644
--- a/unit_tests/test_Errata.cc
+++ b/unit_tests/test_Errata.cc
@@ -214,18 +214,31 @@ TEST_CASE("Errata example", "[libswoc][Errata]") {
   Errata errata{ec, ERRATA_ERROR, R"(Failed to open file "{}")", path};
   w.print("{}", errata);
   REQUIRE(w.size() > 0);
-  REQUIRE(w.view().starts_with("Error [enoent") == true);
+  REQUIRE(w.view().starts_with("Error: [enoent") == true);
   REQUIRE(w.view().find("enoent") != swoc::TextView::npos);
 }
 
 TEST_CASE("Errata local severity", "[libswoc][Errata]") {
   std::string s;
-  Errata errata{ERRATA_ERROR, "Nominal failure"};
-  NoteInfo(errata, "Some");
-  errata.note(ERRATA_DIAG, "error code {}", std::error_code(EPERM, std::system_category()));
-  swoc::bwprint(s, "{}", errata);
-  REQUIRE(s.size() > 0);
-  REQUIRE(std::string::npos != s.find("Error Nominal"));
-  REQUIRE(std::string::npos != s.find("Info Some"));
-  REQUIRE(std::string::npos != s.find("Diag error"));
+  {
+    Errata errata{ERRATA_ERROR, "Nominal failure"};
+    NoteInfo(errata, "Some");
+    errata.note(ERRATA_DIAG, "error code {}", std::error_code(EPERM, std::system_category()));
+    swoc::bwprint(s, "{}", errata);
+    REQUIRE(s.size() > 0);
+    REQUIRE(std::string::npos != s.find("Error: Nominal"));
+    REQUIRE(std::string::npos != s.find("Info: Some"));
+    REQUIRE(std::string::npos != s.find("Diag: error"));
+  }
+  Errata::FILTER_SEVERITY = ERRATA_INFO; // diag is lesser serverity, shouldn't show up.
+  {
+    Errata errata{ERRATA_ERROR, "Nominal failure"};
+    NoteInfo(errata, "Some");
+    errata.note(ERRATA_DIAG, "error code {}", std::error_code(EPERM, std::system_category()));
+    swoc::bwprint(s, "{}", errata);
+    REQUIRE(s.size() > 0);
+    REQUIRE(std::string::npos != s.find("Error: Nominal"));
+    REQUIRE(std::string::npos != s.find("Info: Some"));
+    REQUIRE(std::string::npos == s.find("Diag: error"));
+  }
 }