From: Amos Jeffries Date: Sun, 12 Jul 2015 10:04:45 +0000 (-0700) Subject: Shuffle _TIMEOUT and _ABORTED flags into class LogTags X-Git-Tag: merge-candidate-3-v1~38^2~18^2~1 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=a981b36082d0a0da4ac819c3cc4430c137250ae3;p=thirdparty%2Fsquid.git Shuffle _TIMEOUT and _ABORTED flags into class LogTags --- diff --git a/src/AccessLogEntry.h b/src/AccessLogEntry.h index 30f45f1fb7..f9dbd917cd 100644 --- a/src/AccessLogEntry.h +++ b/src/AccessLogEntry.h @@ -67,8 +67,6 @@ public: method(Http::METHOD_NONE), code(0), content_type(NULL), - timedout(false), - aborted(false), clientRequestSz(), clientReplySz() {} @@ -76,13 +74,6 @@ public: int code; const char *content_type; AnyP::ProtocolVersion version; - bool timedout; ///< terminated due to a lifetime or I/O timeout - bool aborted; ///< other abnormal termination (e.g., I/O error) - - /// compute suffix for the status access.log field - const char *statusSfx() const { - return timedout ? "_TIMEDOUT" : (aborted ? "_ABORTED" : ""); - } /// counters for the original request received from client // TODO calculate header and payload better (by parser) diff --git a/src/LogTags.cc b/src/LogTags.cc index 1a3e5f56c8..8f4d30eb60 100644 --- a/src/LogTags.cc +++ b/src/LogTags.cc @@ -37,10 +37,30 @@ const char * LogTags::Str_[] = { "TYPE_MAX" }; +/* + * This method is documented in http://wiki.squid-cache.org/SquidFaq/SquidLogs#Squid_result_codes + * Please keep the wiki up to date + */ const char * LogTags::c_str() const { - return Str_[oldType]; + static char buf[1024]; + *buf = 0; + int pos = 0; + + // source tags + if (oldType && oldType < LOG_TYPE_MAX) + pos += snprintf(buf, sizeof(buf), "%s",Str_[oldType]); + else + pos += snprintf(buf, sizeof(buf), "NONE"); + + // error tags + if (err.timedout) + pos += snprintf(buf+pos,sizeof(buf)-pos, "_TIMEDOUT"); + if (err.aborted) + pos += snprintf(buf+pos,sizeof(buf)-pos, "_ABORTED"); + + return buf; } bool diff --git a/src/LogTags.h b/src/LogTags.h index bc50befbca..788cf830ab 100644 --- a/src/LogTags.h +++ b/src/LogTags.h @@ -50,11 +50,20 @@ public: LogTags(LogTags_ot t) : oldType(t) {assert(oldType < LOG_TYPE_MAX);} LogTags &operator =(const LogTags_ot &t) {assert(t < LOG_TYPE_MAX); oldType = t; return *this;} + /// compute the status access.log field const char *c_str() const; /// determine if the log tag code indicates a cache HIT bool isTcpHit() const; + /// error states terminating the transaction + struct Errors { + Errors() : timedout(false), aborted(false) {} + + bool timedout; ///< tag: TIMEDOUT - terminated due to a lifetime or I/O timeout + bool aborted; ///< tag: ABORTED - other abnormal termination (e.g., I/O error) + } err; + private: /// list of string representations for LogTags_ot static const char *Str_[]; diff --git a/src/client_side.cc b/src/client_side.cc index 9fe2f14ca3..eb3c12c85d 100644 --- a/src/client_side.cc +++ b/src/client_side.cc @@ -1771,10 +1771,9 @@ void ClientSocketContext::noteIoError(const int xerrno) { if (http) { - if (xerrno == ETIMEDOUT) - http->al->http.timedout = true; - else // even if xerrno is zero (which means read abort/eof) - http->al->http.aborted = true; + http->logType.err.timedout = (xerrno == ETIMEDOUT); + // aborted even if xerrno is zero (which means read abort/eof) + http->logType.err.aborted = (xerrno != ETIMEDOUT); } } @@ -3361,7 +3360,7 @@ clientLifetimeTimeout(const CommTimeoutCbParams &io) ClientHttpRequest *http = static_cast(io.data); debugs(33, DBG_IMPORTANT, "WARNING: Closing client connection due to lifetime timeout"); debugs(33, DBG_IMPORTANT, "\t" << http->uri); - http->al->http.timedout = true; + http->logType.err.timedout = true; if (Comm::IsConnOpen(io.conn)) io.conn->close(); } diff --git a/src/format/Format.cc b/src/format/Format.cc index 7273cb3e5c..ca5fd9e595 100644 --- a/src/format/Format.cc +++ b/src/format/Format.cc @@ -877,13 +877,7 @@ Format::Format::assemble(MemBuf &mb, const AccessLogEntry::Pointer &al, int logS break; case LFT_SQUID_STATUS: - if (al->http.timedout || al->http.aborted) { - snprintf(tmp, sizeof(tmp), "%s%s", al->cache.code.c_str(), al->http.statusSfx()); - out = tmp; - } else { - out = al->cache.code.c_str(); - } - + out = al->cache.code.c_str(); break; case LFT_SQUID_ERROR: diff --git a/src/log/FormatHttpdCombined.cc b/src/log/FormatHttpdCombined.cc index d57382b2e5..03b4607a26 100644 --- a/src/log/FormatHttpdCombined.cc +++ b/src/log/FormatHttpdCombined.cc @@ -51,7 +51,7 @@ Log::Format::HttpdCombined(const AccessLogEntry::Pointer &al, Logfile * logfile) else method = al->http.method.image(); - logfilePrintf(logfile, "%s %s %s [%s] \"" SQUIDSBUFPH " %s %s/%d.%d\" %d %" PRId64 " \"%s\" \"%s\" %s%s:%s%s", + logfilePrintf(logfile, "%s %s %s [%s] \"" SQUIDSBUFPH " %s %s/%d.%d\" %d %" PRId64 " \"%s\" \"%s\" %s:%s%s", clientip, user_ident ? user_ident : dash_str, user_auth ? user_auth : dash_str, @@ -65,7 +65,6 @@ Log::Format::HttpdCombined(const AccessLogEntry::Pointer &al, Logfile * logfile) referer, agent, al->cache.code.c_str(), - al->http.statusSfx(), hier_code_str[al->hier.code], (Config.onoff.log_mime_hdrs?"":"\n")); diff --git a/src/log/FormatHttpdCommon.cc b/src/log/FormatHttpdCommon.cc index bddb71fc6a..3421d03b1e 100644 --- a/src/log/FormatHttpdCommon.cc +++ b/src/log/FormatHttpdCommon.cc @@ -38,7 +38,7 @@ Log::Format::HttpdCommon(const AccessLogEntry::Pointer &al, Logfile * logfile) else method = al->http.method.image(); - logfilePrintf(logfile, "%s %s %s [%s] \"" SQUIDSBUFPH " %s %s/%d.%d\" %d %" PRId64 " %s%s:%s%s", + logfilePrintf(logfile, "%s %s %s [%s] \"" SQUIDSBUFPH " %s %s/%d.%d\" %d %" PRId64 " %s:%s%s", clientip, user_ident ? user_ident : dash_str, user_auth ? user_auth : dash_str, @@ -50,7 +50,6 @@ Log::Format::HttpdCommon(const AccessLogEntry::Pointer &al, Logfile * logfile) al->http.code, al->http.clientReplySz.messageTotal(), al->cache.code.c_str(), - al->http.statusSfx(), hier_code_str[al->hier.code], (Config.onoff.log_mime_hdrs?"":"\n")); diff --git a/src/log/FormatSquidNative.cc b/src/log/FormatSquidNative.cc index e221643120..59ccc6edb5 100644 --- a/src/log/FormatSquidNative.cc +++ b/src/log/FormatSquidNative.cc @@ -54,13 +54,12 @@ Log::Format::SquidNative(const AccessLogEntry::Pointer &al, Logfile * logfile) else method = al->http.method.image(); - logfilePrintf(logfile, "%9ld.%03d %6ld %s %s%s/%03d %" PRId64 " " SQUIDSBUFPH " %s %s %s%s/%s %s%s", + logfilePrintf(logfile, "%9ld.%03d %6ld %s %s/%03d %" PRId64 " " SQUIDSBUFPH " %s %s %s%s/%s %s%s", (long int) current_time.tv_sec, (int) current_time.tv_usec / 1000, tvToMsec(al->cache.trTime), clientip, al->cache.code.c_str(), - al->http.statusSfx(), al->http.code, al->http.clientReplySz.messageTotal(), SQUIDSBUFPRINT(method),