Updated Branches: refs/heads/consistent-gzip-error-msgs 891ada6c7 -> fda89b48d
transform libloader, stats_over_http to new logging non-API - fix typo Project: http://git-wip-us.apache.org/repos/asf/trafficserver/repo Commit: http://git-wip-us.apache.org/repos/asf/trafficserver/commit/4f27dcad Tree: http://git-wip-us.apache.org/repos/asf/trafficserver/tree/4f27dcad Diff: http://git-wip-us.apache.org/repos/asf/trafficserver/diff/4f27dcad Branch: refs/heads/consistent-gzip-error-msgs Commit: 4f27dcadaf0bdc02a4de818c08daf06f211ed23e Parents: 891ada6 Author: Igor GaliÄ <[email protected]> Authored: Thu Aug 8 22:07:49 2013 +0200 Committer: Igor GaliÄ <[email protected]> Committed: Thu Aug 8 22:07:49 2013 +0200 ---------------------------------------------------------------------- plugins/regex_remap/regex_remap.cc | 58 +++++++++++++------------- plugins/stats_over_http/stats_over_http.c | 31 +++++++------- 2 files changed, 46 insertions(+), 43 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/trafficserver/blob/4f27dcad/plugins/regex_remap/regex_remap.cc ---------------------------------------------------------------------- diff --git a/plugins/regex_remap/regex_remap.cc b/plugins/regex_remap/regex_remap.cc index 8b637f6..327e611 100644 --- a/plugins/regex_remap/regex_remap.cc +++ b/plugins/regex_remap/regex_remap.cc @@ -47,7 +47,8 @@ #include "ink_atomic.h" #include "ink_time.h" -static const char* PLUGIN_NAME = "regex_remap"; +#define PLUGIN_NAME "regex_remap" +#include <ts/debug.h> // Constants static const int OVECCOUNT = 30; // We support $0 - $9 x2 ints, and this needs to be 1.5x that @@ -121,13 +122,13 @@ class RemapRegex _num_subs(-1), _rex(NULL), _extra(NULL), _order(-1), _simple(false), _active_timeout(-1), _no_activity_timeout(-1), _connect_timeout(-1), _dns_timeout(-1) { - TSDebug(PLUGIN_NAME, "Calling constructor"); + TSLogDebug("Calling constructor"); _status = static_cast<TSHttpStatus>(0); if (!reg.empty()) { if (reg == ".") { - TSDebug(PLUGIN_NAME, "Rule is simple, and fast!"); + TSLogDebug("Rule is simple, and fast!"); _simple = true; } _rex_string = TSstrdup(reg.c_str()); @@ -158,7 +159,7 @@ class RemapRegex ++start; pos1 = opt.find_first_of("=", start); if (pos1 == std::string::npos) { - TSError("Malformed options: %s", opt.c_str()); + TSLogError("Malformed options: %s", opt.c_str()); break; } ++pos1; @@ -178,7 +179,7 @@ class RemapRegex } else if (opt.compare(start, 11, "dns_timeout") == 0) { _dns_timeout = atoi(opt_val.c_str()); } else { - TSError("Unknown options: %s", opt.c_str()); + TSLogError("Unknown options: %s", opt.c_str()); } start = opt.find_first_of("@", pos2); } @@ -186,7 +187,7 @@ class RemapRegex ~RemapRegex() { - TSDebug(PLUGIN_NAME, "Calling destructor"); + TSLogDebug("Calling destructor"); if (_rex_string) TSfree(_rex_string); if (_subst) @@ -280,7 +281,7 @@ class RemapRegex if (ix > -1) { if ((ix < 10) && (ix > ccount)) { - TSDebug(PLUGIN_NAME, "Trying to use unavailable substitution, check the regex!"); + TSLogDebug("Trying to use unavailable substitution, check the regex!"); return -1; // No substitutions available other than $0 } @@ -554,7 +555,7 @@ TSRemapInit(TSRemapInterface* api_info, char *errbuf, int errbuf_size) } setup_memory_allocation(); - TSDebug(PLUGIN_NAME, "plugin is successfully initialized"); + TSLogInfo("plugin is successfully initialized"); return TS_SUCCESS; } @@ -575,7 +576,7 @@ TSRemapNewInstance(int argc, char* argv[], void** ih, char* /* errbuf ATS_UNUSED *ih = (void*)ri; if (ri == NULL) { - TSError("Unable to create remap instance"); + TSLogError("Unable to create remap instance"); return TS_ERROR; } @@ -607,10 +608,10 @@ TSRemapNewInstance(int argc, char* argv[], void** ih, char* /* errbuf ATS_UNUSED f.open((ri->filename).c_str(), std::ios::in); if (!f.is_open()) { // Try with the default path instead - TSError("unable to open %s", (ri->filename).c_str()); + TSLogError("unable to open %s", (ri->filename).c_str()); return TS_ERROR; } - TSDebug(PLUGIN_NAME, "loading regular expression maps from %s", (ri->filename).c_str()); + TSLogDebug("loading regular expression maps from %s", (ri->filename).c_str()); while (!f.eof()) { std::string line, regex, subst, options; @@ -647,12 +648,12 @@ TSRemapNewInstance(int argc, char* argv[], void** ih, char* /* errbuf ATS_UNUSED if (regex.empty()) { // No regex found on this line - TSError("no regexp found in %s: line %d", (ri->filename).c_str(), lineno); + TSLogError("no regexp found in %s: line %d", (ri->filename).c_str(), lineno); continue; } if (subst.empty() && options.empty()) { // No substitution found on this line (and no options) - TSError("no substitution string found in %s: line %d", (ri->filename).c_str(), lineno); + TSLogError("no substitution string found in %s: line %d", (ri->filename).c_str(), lineno); continue; } @@ -660,16 +661,15 @@ TSRemapNewInstance(int argc, char* argv[], void** ih, char* /* errbuf ATS_UNUSED RemapRegex* cur = new RemapRegex(regex, subst, options); if (cur == NULL) { - TSError("can't create a new regex remap rule"); + TSLogError("can't create a new regex remap rule"); continue; } if (cur->compile(&error, &erroffset) < 0) { - TSError("PCRE failed in %s (line %d) at offset %d: %s", (ri->filename).c_str(), lineno, erroffset, error); + TSLogError("PCRE failed in %s (line %d) at offset %d: %s", (ri->filename).c_str(), lineno, erroffset, error); delete(cur); } else { - TSDebug(PLUGIN_NAME, "added regex=%s with substitution=%s and options `%s'", - regex.c_str(), subst.c_str(), options.c_str()); + TSLogDebug("added regex=%s with substitution=%s and options `%s'", regex.c_str(), subst.c_str(), options.c_str()); cur->set_order(++count); if (ri->first == NULL) ri->first = cur; @@ -683,7 +683,7 @@ TSRemapNewInstance(int argc, char* argv[], void** ih, char* /* errbuf ATS_UNUSED // Make sure we got something... if (ri->first == NULL) { - TSError("Got no regular expressions from the maps"); + TSLogError("Got no regular expressions from the maps"); return TS_ERROR; } @@ -743,7 +743,7 @@ TSRemapStatus TSRemapDoRemap(void* ih, TSHttpTxn txnp, TSRemapRequestInfo *rri) { if (NULL == ih) { - TSDebug(PLUGIN_NAME, "Falling back to default URL on regex remap without rules"); + TSLogDebug("Falling back to default URL on regex remap without rules"); return TSREMAP_NO_REMAP; } @@ -796,7 +796,7 @@ TSRemapDoRemap(void* ih, TSHttpTxn txnp, TSRemapRequestInfo *rri) match_len += (req_url.query_len + 1); } match_buf[match_len] = '\0'; // NULL terminate the match string - TSDebug(PLUGIN_NAME, "Target match string is `%s'", match_buf); + TSLogDebug("Target match string is `%s'", match_buf); // Apply the regular expressions, in order. First one wins. while (re) { @@ -806,19 +806,19 @@ TSRemapDoRemap(void* ih, TSHttpTxn txnp, TSRemapRequestInfo *rri) // Set timeouts if (re->active_timeout_option() > (-1)) { - TSDebug(PLUGIN_NAME, "Setting active timeout to %d", re->active_timeout_option()); + TSLogDebug("Setting active timeout to %d", re->active_timeout_option()); TSHttpTxnActiveTimeoutSet(txnp, re->active_timeout_option()); } if (re->no_activity_timeout_option() > (-1)) { - TSDebug(PLUGIN_NAME, "Setting no activity timeout to %d", re->no_activity_timeout_option()); + TSLogDebug("Setting no activity timeout to %d", re->no_activity_timeout_option()); TSHttpTxnNoActivityTimeoutSet(txnp, re->no_activity_timeout_option()); } if (re->connect_timeout_option() > (-1)) { - TSDebug(PLUGIN_NAME, "Setting connect timeout to %d", re->connect_timeout_option()); + TSLogDebug("Setting connect timeout to %d", re->connect_timeout_option()); TSHttpTxnConnectTimeoutSet(txnp, re->connect_timeout_option()); } if (re->dns_timeout_option() > (-1)) { - TSDebug(PLUGIN_NAME, "Setting DNS timeout to %d", re->dns_timeout_option()); + TSLogDebug("Setting DNS timeout to %d", re->dns_timeout_option()); TSHttpTxnDNSTimeoutSet(txnp, re->dns_timeout_option()); } @@ -834,9 +834,9 @@ TSRemapDoRemap(void* ih, TSHttpTxn txnp, TSRemapRequestInfo *rri) dest = (char*)alloca(new_len+8); dest_len = re->substitute(dest, match_buf, ovector, lengths, rri, &req_url); - TSDebug(PLUGIN_NAME, "New URL is estimated to be %d bytes long, or less", new_len); - TSDebug(PLUGIN_NAME, "New URL is %s (length %d)", dest, dest_len); - TSDebug(PLUGIN_NAME, " matched rule %d [%s]", re->order(), re->regex()); + TSLogDebug("New URL is estimated to be %d bytes long, or less", new_len); + TSLogDebug("New URL is %s (length %d)", dest, dest_len); + TSLogDebug(" matched rule %d [%s]", re->order(), re->regex()); // Check for a quick response, if the status option is set if (re->status_option() > 0) { @@ -847,7 +847,7 @@ TSRemapDoRemap(void* ih, TSHttpTxn txnp, TSRemapRequestInfo *rri) break; } - TSDebug(PLUGIN_NAME, "Redirecting URL, status=%d", re->status_option()); + TSLogDebug("Redirecting URL, status=%d", re->status_option()); TSHttpTxnSetHttpRetStatus(txnp, re->status_option()); rri->redirect = 1; } @@ -859,7 +859,7 @@ TSRemapDoRemap(void* ih, TSHttpTxn txnp, TSRemapRequestInfo *rri) // Setup the new URL if (TS_PARSE_ERROR == TSUrlParse(rri->requestBufp, rri->requestUrl, &start, start + dest_len)) { TSHttpTxnSetHttpRetStatus(txnp, TS_HTTP_STATUS_INTERNAL_SERVER_ERROR); - TSError("can't parse substituted URL string"); + TSLogError("can't parse substituted URL string"); } } break; http://git-wip-us.apache.org/repos/asf/trafficserver/blob/4f27dcad/plugins/stats_over_http/stats_over_http.c ---------------------------------------------------------------------- diff --git a/plugins/stats_over_http/stats_over_http.c b/plugins/stats_over_http/stats_over_http.c index 89a13af..5cfb8db 100644 --- a/plugins/stats_over_http/stats_over_http.c +++ b/plugins/stats_over_http/stats_over_http.c @@ -39,6 +39,9 @@ static const char* url_path = "_stats"; static int url_path_len; +#define PLUGIN_NAME "stats_ver_http" +#include <ts/debug.h> + typedef struct stats_state_t { TSVConn net_vc; @@ -102,20 +105,20 @@ stats_add_resp_header(stats_state * my_state) static void stats_process_read(TSCont contp, TSEvent event, stats_state * my_state) { - TSDebug("istats", "stats_process_read(%d)", event); + TSLogDebug("event: %d", event); if (event == TS_EVENT_VCONN_READ_READY) { my_state->output_bytes = stats_add_resp_header(my_state); TSVConnShutdown(my_state->net_vc, 1, 0); my_state->write_vio = TSVConnWrite(my_state->net_vc, contp, my_state->resp_reader, INT64_MAX); } else if (event == TS_EVENT_ERROR) { - TSError("stats_process_read: Received TS_EVENT_ERROR\n"); + TSLogError("Received TS_EVENT_ERROR"); } else if (event == TS_EVENT_VCONN_EOS) { /* client may end the connection, simply return */ return; } else if (event == TS_EVENT_NET_ACCEPT_FAILED) { - TSError("stats_process_read: Received TS_EVENT_NET_ACCEPT_FAILED\n"); + TSLogError("Received TS_EVENT_NET_ACCEPT_FAILED"); } else { - printf("Unexpected Event %d\n", event); + TSLogError("Unexpected Event %d", event); TSReleaseAssert(!"Unexpected Event"); } } @@ -143,7 +146,7 @@ json_out_stat(TSRecordType rec_type ATS_UNUSED, void *edata, int registered ATS_ case TS_RECORDDATATYPE_STRING: APPEND_STAT(name, "%s", datum->rec_string); break; default: - TSDebug("istats", "unknown type for %s: %d", name, data_type); + TSLogDebug("unknown type for %s: %d", name, data_type); break; } } @@ -166,7 +169,7 @@ stats_process_write(TSCont contp, TSEvent event, stats_state * my_state) { if (event == TS_EVENT_VCONN_WRITE_READY) { if (my_state->body_written == 0) { - TSDebug("istats", "plugin adding response body"); + TSLogDebug("plugin adding response body"); my_state->body_written = 1; json_out_stats(my_state); TSVIONBytesSet(my_state->write_vio, my_state->output_bytes); @@ -175,7 +178,7 @@ stats_process_write(TSCont contp, TSEvent event, stats_state * my_state) } else if (TS_EVENT_VCONN_WRITE_COMPLETE) { stats_cleanup(contp, my_state); } else if (event == TS_EVENT_ERROR) { - TSError("stats_process_write: Received TS_EVENT_ERROR\n"); + TSLogError("Received TS_EVENT_ERROR"); } else { TSReleaseAssert(!"Unexpected Event"); } @@ -208,7 +211,7 @@ stats_origin(TSCont contp ATS_UNUSED, TSEvent event ATS_UNUSED, void *edata) TSMLoc hdr_loc = NULL, url_loc = NULL; TSEvent reenable = TS_EVENT_HTTP_CONTINUE; - TSDebug("istats", "in the read stuff"); + TSLogDebug("in the read stuff"); if (TSHttpTxnClientReqGet(txnp, &reqp, &hdr_loc) != TS_SUCCESS) goto cleanup; @@ -218,7 +221,7 @@ stats_origin(TSCont contp ATS_UNUSED, TSEvent event ATS_UNUSED, void *edata) int path_len = 0; const char* path = TSUrlPathGet(reqp,url_loc,&path_len); - TSDebug("istats","Path: %.*s",path_len,path); + TSLogDebug("Path: %.*s",path_len,path); if (! (path_len != 0 && path_len == url_path_len && !memcmp(path,url_path,url_path_len)) ) { goto notforme; @@ -227,7 +230,7 @@ stats_origin(TSCont contp ATS_UNUSED, TSEvent event ATS_UNUSED, void *edata) TSSkipRemappingSet(txnp,1); //not strictly necessary, but speed is everything these days /* This is us -- register our intercept */ - TSDebug("istats", "Intercepting request"); + TSLogDebug("Intercepting request"); icontp = TSContCreate(stats_dostuff, TSMutexCreate()); my_state = (stats_state *) TSmalloc(sizeof(*my_state)); @@ -254,12 +257,12 @@ TSPluginInit(int argc, const char *argv[]) { TSPluginRegistrationInfo info; - info.plugin_name = "stats"; + info.plugin_name = "stats_over_http"; info.vendor_name = "Apache Software Foundation"; - info.support_email = "[email protected]"; + info.support_email = "[email protected]"; if (TSPluginRegister(TS_SDK_VERSION_2_0, &info) != TS_SUCCESS) - TSError("Plugin registration failed. \n"); + TSLogError("Plugin registration failed. \n"); if (argc > 1) { url_path = TSstrdup(argv[1] + ('/' == argv[1][0] ? 1 : 0)); /* Skip leading / */ @@ -269,5 +272,5 @@ TSPluginInit(int argc, const char *argv[]) /* Create a continuation with a mutex as there is a shared global structure containing the headers to add */ TSHttpHookAdd(TS_HTTP_READ_REQUEST_HDR_HOOK, TSContCreate(stats_origin, NULL)); - TSDebug("istats", "stats module registered"); + TSLogInfo("stats module registered"); }
