transform balancer to new logging non-API
Project: http://git-wip-us.apache.org/repos/asf/trafficserver/repo Commit: http://git-wip-us.apache.org/repos/asf/trafficserver/commit/380aab33 Tree: http://git-wip-us.apache.org/repos/asf/trafficserver/tree/380aab33 Diff: http://git-wip-us.apache.org/repos/asf/trafficserver/diff/380aab33 Branch: refs/heads/consistent-gzip-error-msgs Commit: 380aab331a05d429f725e8e8413e9d38177b2c4c Parents: 6474144 Author: Igor GaliÄ <[email protected]> Authored: Thu Aug 8 22:25:32 2013 +0200 Committer: Igor GaliÄ <[email protected]> Committed: Thu Aug 8 22:25:32 2013 +0200 ---------------------------------------------------------------------- plugins/experimental/balancer/balancer.cc | 48 +++++++++++++------------- plugins/experimental/balancer/resources.h | 9 +++-- 2 files changed, 30 insertions(+), 27 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/trafficserver/blob/380aab33/plugins/experimental/balancer/balancer.cc ---------------------------------------------------------------------- diff --git a/plugins/experimental/balancer/balancer.cc b/plugins/experimental/balancer/balancer.cc index adc91ad..4b2cd2b 100644 --- a/plugins/experimental/balancer/balancer.cc +++ b/plugins/experimental/balancer/balancer.cc @@ -89,7 +89,7 @@ public: char* rotation() const { return _rotation; }; void set_rotation(const std::string& rot) { if (rot.size() > 255) { - TSError("Rotation name is too long"); + TSLogError("Rotation name is too long"); return; } _rotation = TSstrdup(rot.c_str()); @@ -148,8 +148,8 @@ public: hk = hk->next; } *p = '\0'; - if (TSIsDebugTagSet("balancer")) { - TSDebug("balancer", "Making %s hash ID's using %s", secondary ? "secondary" : "primary", buf); + if (TSIsDebugTagSet(PLUGIN_NAME)) { + TSLogDebug("Making %s hash ID's using %s", secondary ? "secondary" : "primary", buf); } ycrMD5_r(buf, key_len, id); } else { @@ -159,7 +159,7 @@ public: *buf = resr.getRRI()->client_ip; // ToDo: this only works for IPv4 - TSDebug("balancer", "Making secondary hash ID's using IP (default) = %s", buf); + TSLogDebug("Making secondary hash ID's using IP (default) = %s", buf); ycrMD5_r(buf, key_len, id); } else { // Primary ID defaults to URL (if none of the specified hashes computes) @@ -167,7 +167,7 @@ public: memcpy(buf, resr.getRRI()->orig_url, resr.getRRI()->orig_url_size); buf[resr.getRRI()->orig_url_size] = '\0'; - TSDebug("balancer", "Making primary hash ID's using URL (default) = %s", buf); + TSLogDebug("Making primary hash ID's using URL (default) = %s", buf); ycrMD5_r(buf, key_len, id); } } @@ -208,7 +208,7 @@ tsremap_init(TSREMAP_INTERFACE *api_info, char *errbuf, int errbuf_size) return -3; } - TSDebug("balancer", "plugin is successfully initialized"); + TSLogInfo("plugin is successfully initialized"); return 0; } @@ -224,7 +224,7 @@ tsremap_new_instance(int argc, char *argv[], ihandle *ih, char *errbuf, int errb *ih = static_cast<ihandle>(ri); if (ri == NULL) { - TSError("Unable to create remap instance"); + TSLogError("Unable to create remap instance"); return -5; } @@ -238,7 +238,7 @@ tsremap_new_instance(int argc, char *argv[], ihandle *ih, char *errbuf, int errb std::string::size_type sep = arg.find_first_of(":"); if (sep == std::string::npos) { - TSError("Malformed options in balancer: %s", argv[ix]); + TSLogError("Malformed options in balancer: %s", argv[ix]); } else { std::string arg_val = arg.substr(sep + 1, std::string::npos); @@ -253,7 +253,7 @@ tsremap_new_instance(int argc, char *argv[], ihandle *ih, char *errbuf, int errb URLHashKey* hk = new URLHashKey(); if (NULL == hk) { - TSError("Couldn't create balancer URL hash key"); + TSLogError("Couldn't create balancer URL hash key"); } else { ri->append_hash(hk, secondary); } @@ -261,7 +261,7 @@ tsremap_new_instance(int argc, char *argv[], ihandle *ih, char *errbuf, int errb PathHashKey* hk = new PathHashKey(); if (NULL == hk) { - TSError("Couldn't create balancer path hash key"); + TSLogError("Couldn't create balancer path hash key"); } else { ri->append_hash(hk, secondary); } @@ -269,7 +269,7 @@ tsremap_new_instance(int argc, char *argv[], ihandle *ih, char *errbuf, int errb IPHashKey* hk = new IPHashKey(); if (NULL == hk) { - TSError("Couldn't create balancer IP hash key"); + TSLogError("Couldn't create balancer IP hash key"); } else { ri->append_hash(hk, secondary); } @@ -278,7 +278,7 @@ tsremap_new_instance(int argc, char *argv[], ihandle *ih, char *errbuf, int errb std::string::size_type sep2 = arg_val.find_first_of("/"); if (sep2 == std::string::npos) { - TSError("Malformed hash options in balancer: %s", argv[ix]); + TSLogError("Malformed hash options in balancer: %s", argv[ix]); } else { std::string arg_val2 = arg_val.substr(sep2 + 1, std::string::npos); @@ -286,7 +286,7 @@ tsremap_new_instance(int argc, char *argv[], ihandle *ih, char *errbuf, int errb CookieHashKey* hk = new CookieHashKey(arg_val2); if (NULL == hk) { - TSError("Couldn't create balancer cookie hash key"); + TSLogError("Couldn't create balancer cookie hash key"); } else { ri->append_hash(hk, secondary); } @@ -294,17 +294,17 @@ tsremap_new_instance(int argc, char *argv[], ihandle *ih, char *errbuf, int errb HeaderHashKey* hk = new HeaderHashKey(arg_val2); if (NULL == hk) { - TSError("Couldn't create balancer header hash key"); + TSLogError("Couldn't create balancer header hash key"); } else { ri->append_hash(hk, secondary); } } else { - TSError("Unknown balancer hash option: %s", argv[ix]); + TSLogError("Unknown balancer hash option: %s", argv[ix]); } } } } else { - TSError("Unknown balancer option: %s", argv[ix]); + TSLogError("Unknown balancer option: %s", argv[ix]); } } } @@ -337,7 +337,7 @@ tsremap_remap(ihandle ih, rhandle rh, REMAP_REQUEST_INFO *rri) char *rot; if (NULL == ih) { - TSDebug("balancer", "Falling back to default URL on remap without rules"); + TSLogDebug("Falling back to default URL on remap without rules"); return 0; } balancer = static_cast<BalancerInstance*>(ih); @@ -382,33 +382,33 @@ tsremap_remap(ihandle ih, rhandle rh, REMAP_REQUEST_INFO *rri) balancer_info.secondary_id = id2; balancer_info.secondary_id_len = MD5_DIGEST_LENGTH; - TSDebug("balancer", "Calling balancer_lookup(\"%s\") with primary and secondary hash", rot); + TSLogDebug("Calling balancer_lookup(\"%s\") with primary and secondary hash", rot); res = balancer_lookup(rot, &balancer_info); } else { - TSDebug("balancer", "Calling balancer_lookup(\"%s\") with primary hash", rot); + TSLogDebug("Calling balancer_lookup(\"%s\") with primary hash", rot); res = balancer_lookup(rot, &balancer_info); } } else { - TSDebug("balancer", "Calling balancer_lookup(\"%s\") without hash", rot); + TSLogDebug("Calling balancer_lookup(\"%s\") without hash", rot); res = balancer_lookup(rot, &balancer_info); } // Check (and use) the balancer lookup results if (!res) { - TSDebug("balancer", "BALANCER has no data for %s, using To-URL (error is %d)", rot, balancer_error); + TSLogDebug("BALANCER has no data for %s, using To-URL (error is %d)", rot, balancer_error); return 0; } else { if ((balancer_port > 0) && (balancer_port != rri->remap_to_port)) { rri->new_port = balancer_port; - TSDebug("balancer", "Changing request to port %d", balancer_port); + TSLogDebug("Changing request to port %d", balancer_port); } if (balancer->host_ip()) { unsigned char *ip = (unsigned char*)res->h_addr; rri->new_host_size = snprintf(rri->new_host, 16, "%d.%d.%d.%d", ip[0], ip[1], ip[2], ip[3]); - TSDebug("balancer", "Setting real-host IP to %.*s (IP for %s)", rri->new_host_size, rri->new_host, res->h_name); + TSLogDebug("Setting real-host IP to %.*s (IP for %s)", rri->new_host_size, rri->new_host, res->h_name); } else { - TSDebug("balancer", "Setting real-host to %s", res->h_name); + TSLogDebug("Setting real-host to %s", res->h_name); rri->new_host_size = strlen(res->h_name); if (rri->new_host_size > TSREMAP_RRI_MAX_HOST_SIZE) rri->new_host_size = TSREMAP_RRI_MAX_HOST_SIZE; http://git-wip-us.apache.org/repos/asf/trafficserver/blob/380aab33/plugins/experimental/balancer/resources.h ---------------------------------------------------------------------- diff --git a/plugins/experimental/balancer/resources.h b/plugins/experimental/balancer/resources.h index 6188951..3f9b1dc 100644 --- a/plugins/experimental/balancer/resources.h +++ b/plugins/experimental/balancer/resources.h @@ -33,6 +33,9 @@ #include <ts/ts.h> +#define PLUGIN_NAME "balancer" +#include <ts/debug.h> + /////////////////////////////////////////////////////////////////////////////// // Class declaration @@ -46,12 +49,12 @@ public: ~Resources() { if (_hdrLoc) { - TSDebug("balancer", "Releasing the client request headers"); + TSLogDebug("Releasing the client request headers"); TSHandleMLocRelease(_bufp, TS_NULL_MLOC, _hdrLoc); } if (_jar) { - TSDebug("balancer", "Destroying the cookie jar"); + TSLogDebug("Destroying the cookie jar"); // TODO - destroy cookies } } @@ -72,7 +75,7 @@ public: memcpy(cookie_hdr, _rri->request_cookie, _rri->request_cookie_size); cookie_hdr[_rri->request_cookie_size] = '\0'; _jar = // TODO - create cookies - TSDebug("balancer", "Creating the cookie jar"); + TSLogDebug("Creating the cookie jar"); } return _jar;
