You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by bc...@apache.org on 2019/01/18 17:03:46 UTC
[trafficserver] branch master updated: Add log method overload for
string_view to LogObject.
This is an automated email from the ASF dual-hosted git repository.
bcall pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficserver.git
The following commit(s) were added to refs/heads/master by this push:
new e18d65a Add log method overload for string_view to LogObject.
e18d65a is described below
commit e18d65a147ad91acd6baccadd2f641e1f7e25304
Author: Alan M. Carroll <am...@apache.org>
AuthorDate: Wed Jan 16 13:13:05 2019 -0600
Add log method overload for string_view to LogObject.
---
proxy/logging/LogObject.cc | 19 ++++++++++++++-----
proxy/logging/LogObject.h | 11 +++++++++++
2 files changed, 25 insertions(+), 5 deletions(-)
diff --git a/proxy/logging/LogObject.cc b/proxy/logging/LogObject.cc
index 9f765da..336815c 100644
--- a/proxy/logging/LogObject.cc
+++ b/proxy/logging/LogObject.cc
@@ -533,6 +533,13 @@ LogObject::va_log(LogAccess *lad, const char *fmt, va_list ap)
int
LogObject::log(LogAccess *lad, const char *text_entry)
{
+ // Clang doesn't like initializing a view with nullptr, have to check.
+ return this->log(lad, std::string_view{text_entry ? text_entry : ""});
+}
+
+int
+LogObject::log(LogAccess *lad, std::string_view text_entry)
+{
LogBuffer *buffer;
size_t offset = 0; // prevent warning
size_t bytes_needed = 0, bytes_used = 0;
@@ -546,7 +553,7 @@ LogObject::log(LogAccess *lad, const char *text_entry)
}
// this verification must be done here in order to avoid 'dead' LogBuffers
// with none zero 'in usage' counters (see _checkout_write for more details)
- if (!lad && !text_entry) {
+ if (!lad && text_entry.empty()) {
Note("Call to LogAccess without LAD or text entry; skipping");
return Log::FAIL;
}
@@ -596,8 +603,8 @@ LogObject::log(LogAccess *lad, const char *text_entry)
bytes_needed = m_format->field_count() * INK_MIN_ALIGN;
} else if (lad) {
bytes_needed = m_format->m_field_list.marshal_len(lad);
- } else if (text_entry) {
- bytes_needed = LogAccess::strlen(text_entry);
+ } else if (!text_entry.empty()) {
+ bytes_needed = INK_ALIGN_DEFAULT(text_entry.size() + 1); // must include null terminator.
}
if (bytes_needed == 0) {
@@ -630,8 +637,10 @@ LogObject::log(LogAccess *lad, const char *text_entry)
} else if (lad) {
bytes_used = m_format->m_field_list.marshal(lad, &(*buffer)[offset]);
ink_assert(bytes_needed >= bytes_used);
- } else if (text_entry) {
- ink_strlcpy(&(*buffer)[offset], text_entry, bytes_needed);
+ } else if (!text_entry.empty()) {
+ char *dst = &(*buffer)[offset];
+ memcpy(dst, text_entry.data(), text_entry.size());
+ memset(dst + text_entry.size(), 0, bytes_needed - text_entry.size());
}
buffer->checkin_write(offset);
diff --git a/proxy/logging/LogObject.h b/proxy/logging/LogObject.h
index 3dc50e2..9c59b84 100644
--- a/proxy/logging/LogObject.h
+++ b/proxy/logging/LogObject.h
@@ -119,6 +119,17 @@ public:
}
int log(LogAccess *lad, const char *text_entry = nullptr);
+
+ /** Log the @a text_entry.
+ *
+ * @param lad Log accessor.
+ * @param text_entry Literal text to log.
+ * @return Result - value from Log::ReturnCodeFlags.
+ *
+ * @see Log::ReturnCodeFlags.
+ */
+ int log(LogAccess *lad, std::string_view text_entry);
+
int va_log(LogAccess *lad, const char *fmt, va_list ap);
unsigned roll_files(long time_now = 0);