You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by jp...@apache.org on 2013/10/31 16:18:26 UTC
[07/17] git commit: TS-2302: add LogObject::va_log() and use it to
implement TextLogObject message formatting
TS-2302: add LogObject::va_log() and use it to implement TextLogObject message formatting
Project: http://git-wip-us.apache.org/repos/asf/trafficserver/repo
Commit: http://git-wip-us.apache.org/repos/asf/trafficserver/commit/e37f7497
Tree: http://git-wip-us.apache.org/repos/asf/trafficserver/tree/e37f7497
Diff: http://git-wip-us.apache.org/repos/asf/trafficserver/diff/e37f7497
Branch: refs/heads/master
Commit: e37f74978ae5fcf2cc4e9dc14d8db35024738dd0
Parents: c078edf
Author: James Peach <jp...@apache.org>
Authored: Wed Oct 2 10:54:30 2013 -0700
Committer: James Peach <jp...@apache.org>
Committed: Thu Oct 31 08:16:27 2013 -0700
----------------------------------------------------------------------
proxy/logging/Log.cc | 2 +-
proxy/logging/LogObject.cc | 69 ++++++++++++++++++++++-------------------
proxy/logging/LogObject.h | 12 +++----
3 files changed, 44 insertions(+), 39 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/e37f7497/proxy/logging/Log.cc
----------------------------------------------------------------------
diff --git a/proxy/logging/Log.cc b/proxy/logging/Log.cc
index 4dd8dc1..a5e5c22 100644
--- a/proxy/logging/Log.cc
+++ b/proxy/logging/Log.cc
@@ -1167,7 +1167,7 @@ Log::va_error(const char *format, va_list ap)
if (error_log) {
ink_assert(format != NULL);
- ret_val = error_log->va_write(format, ap);
+ ret_val = error_log->va_log(NULL, format, ap);
switch (ret_val) {
case Log::LOG_OK:
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/e37f7497/proxy/logging/LogObject.cc
----------------------------------------------------------------------
diff --git a/proxy/logging/LogObject.cc b/proxy/logging/LogObject.cc
index ce86692..24e4d57 100644
--- a/proxy/logging/LogObject.cc
+++ b/proxy/logging/LogObject.cc
@@ -510,7 +510,38 @@ LogObject::_checkout_write(size_t * write_offset, size_t bytes_needed) {
int
-LogObject::log(LogAccess * lad, char *text_entry)
+LogObject::va_log(LogAccess * lad, const char * fmt, va_list ap)
+{
+ static const unsigned MAX_ENTRY = 16 * LOG_KILOBYTE; // 16K? Really?
+ char entry[MAX_ENTRY];
+ unsigned len = 0;
+
+ ink_assert(fmt != NULL);
+ len = 0;
+
+ if (this->m_flags & LOG_OBJECT_FMT_TIMESTAMP) {
+ len = LogUtils::timestamp_to_str(LogUtils::timestamp(), entry, MAX_ENTRY);
+ if (len <= 0) {
+ return Log::FAIL;
+ }
+
+ // Add a space after the timestamp
+ entry[len++] = ' ';
+
+ if (len >= MAX_ENTRY) {
+ return Log::FAIL;
+ }
+ }
+
+ len += vsnprintf(&entry[len], MAX_ENTRY - len, fmt, ap);
+
+ // Now that we have an entry and it's length (len), we can place it
+ // into the associated logbuffer.
+ return this->log(lad, entry);
+}
+
+int
+LogObject::log(LogAccess * lad, const char *text_entry)
{
LogBuffer *buffer;
size_t offset = 0; // prevent warning
@@ -802,8 +833,11 @@ TextLogObject::TextLogObject(const char *name, const char *log_dir,
int rolling_size_mb)
: LogObject(NEW(new LogFormat(TEXT_LOG)), log_dir, name, ASCII_LOG, header,
rolling_enabled, flush_threads, rolling_interval_sec,
- rolling_offset_hr, rolling_size_mb), m_timestamps(timestamps)
+ rolling_offset_hr, rolling_size_mb)
{
+ if (timestamps) {
+ this->set_fmt_timestamps();
+ }
}
@@ -843,36 +877,7 @@ TextLogObject::write(const char *format, ...)
int
TextLogObject::va_write(const char *format, va_list ap)
{
- static const int MAX_ENTRY = 16 * LOG_KILOBYTE;
- char entry[MAX_ENTRY];
- int len;
-
- ink_assert(format != NULL);
- len = 0;
-
- if (m_timestamps) {
- len = LogUtils::timestamp_to_str(LogUtils::timestamp(), entry, MAX_ENTRY);
- if (len <= 0) {
- return Log::FAIL;
- }
- //
- // Add a space after the timestamp
- //
- entry[len++] = ' ';
- }
-
- if (len >= MAX_ENTRY) {
- return Log::FAIL;
- }
-
- len += vsnprintf(&entry[len], MAX_ENTRY - len, format, ap);
-
- //
- // Now that we have an entry and it's length (len), we can place it
- // into the associated logbuffer.
- //
-
- return log(NULL, entry);
+ return this->va_log(NULL, format, ap);
}
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/e37f7497/proxy/logging/LogObject.h
----------------------------------------------------------------------
diff --git a/proxy/logging/LogObject.h b/proxy/logging/LogObject.h
index 48be36a..72037f2 100644
--- a/proxy/logging/LogObject.h
+++ b/proxy/logging/LogObject.h
@@ -88,7 +88,8 @@ public:
{
BINARY = 1,
REMOTE_DATA = 2,
- WRITES_TO_PIPE = 4
+ WRITES_TO_PIPE = 4,
+ LOG_OBJECT_FMT_TIMESTAMP = 8, // always format a timestamp into each log line (for raw text logs)
};
// BINARY: log is written in binary format (rather than ascii)
@@ -110,8 +111,10 @@ public:
void add_loghost(LogHost * host, bool copy = true);
void set_remote_flag() { m_flags |= REMOTE_DATA; };
+ void set_fmt_timestamps() { m_flags |= LOG_OBJECT_FMT_TIMESTAMP; }
- int log(LogAccess * lad, char *text_entry = NULL);
+ int log(LogAccess * lad, const char *text_entry = NULL);
+ int va_log(LogAccess * lad, const char * fmt, va_list ap);
int roll_files(long time_now = 0);
@@ -259,11 +262,8 @@ public:
int rolling_offset_hr = 0,
int rolling_size_mb = 0);
- inkcoreapi int write(const char *format, ...);
+ inkcoreapi int write(const char *format, ...) TS_PRINTFLIKE(2, 3);
inkcoreapi int va_write(const char *format, va_list ap);
-
-private:
- bool m_timestamps;
};
/*-------------------------------------------------------------------------