transform header_filter 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/4e5cfae7 Tree: http://git-wip-us.apache.org/repos/asf/trafficserver/tree/4e5cfae7 Diff: http://git-wip-us.apache.org/repos/asf/trafficserver/diff/4e5cfae7 Branch: refs/heads/consistent-gzip-error-msgs Commit: 4e5cfae7662ea9bd8ff4bffcb89a30ce2475d697 Parents: 065644e Author: Igor GaliÄ <[email protected]> Authored: Thu Aug 8 18:25:54 2013 +0200 Committer: Igor GaliÄ <[email protected]> Committed: Thu Aug 8 19:39:03 2013 +0200 ---------------------------------------------------------------------- plugins/header_filter/header_filter.cc | 17 ++++++++--------- plugins/header_filter/lulu.h | 4 ++-- plugins/header_filter/rules.cc | 24 ++++++++++++------------ plugins/header_filter/rules.h | 8 ++++---- 4 files changed, 26 insertions(+), 27 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/trafficserver/blob/4e5cfae7/plugins/header_filter/header_filter.cc ---------------------------------------------------------------------- diff --git a/plugins/header_filter/header_filter.cc b/plugins/header_filter/header_filter.cc index 33713e9..8d1737d 100644 --- a/plugins/header_filter/header_filter.cc +++ b/plugins/header_filter/header_filter.cc @@ -69,8 +69,7 @@ cont_header_filter(TSCont /* contp ATS_UNUSED */, TSEvent event, void *edata) hook = TS_HTTP_SEND_RESPONSE_HDR_HOOK; break; default: - TSError("header_filter: unknown event for this plugin"); - TSDebug(PLUGIN_NAME, "unknown event for this plugin"); + TSLogError("Unknown event (%d) for this plugin", event); break; } @@ -105,25 +104,25 @@ TSPluginInit(int argc, const char *argv[]) info.support_email = const_cast<char*>("[email protected]"); if (TSPluginRegister(TS_SDK_VERSION_3_0 , &info) != TS_SUCCESS) { - TSError("header_filter: plugin registration failed.\n"); + TSLogError("plugin registration failed."); } // Parse the rules file if ((argc > 1)) { if (!global.parse_file(argv[1])) - TSError("header_filter: failed to parse configuration file"); + TSLogError("failed to parse configuration file"); } TSCont cont = TSContCreate(cont_header_filter, NULL); for (int i=TS_HTTP_READ_REQUEST_HDR_HOOK; i < TS_HTTP_LAST_HOOK; ++i) { if (global.supported_hook(static_cast<TSHttpHookID>(i))) { - TSDebug(PLUGIN_NAME, "Registering hook %d", i); + TSLogDebug("Registering hook %d", i); TSHttpHookAdd(static_cast<TSHttpHookID>(i), cont); } } if (TSHttpArgIndexReserve(PLUGIN_NAME, "Filter out headers in various hooks", &arg_idx) != TS_SUCCESS) { - TSError("header_filter: failed to reserve private data slot"); + TSLogError("failed to reserve private data slot"); } } @@ -150,7 +149,7 @@ TSRemapInit(TSRemapInterface* api_info, char *errbuf, int errbuf_size) return TS_ERROR; } - TSDebug(PLUGIN_NAME, "remap plugin is successfully initialized"); + TSLogInfo("remap plugin is successfully initialized"); return TS_SUCCESS; /* success */ } @@ -159,7 +158,7 @@ TSReturnCode TSRemapNewInstance(int argc, char* argv[], void** ih, char* /* errbuf ATS_UNUSED */, int /* errbuf_size */) { if (argc < 3) { - TSError("Unable to create remap instance, need rules file"); + TSLogError("Unable to create remap instance, need rules file"); return TS_ERROR; } else { Rules* conf = new(Rules); @@ -187,7 +186,7 @@ TSRemapStatus TSRemapDoRemap(void* ih, TSHttpTxn rh, TSRemapRequestInfo *rri) { if (NULL == ih) { - TSDebug(PLUGIN_NAME, "No Rules configured, falling back to default mapping rule"); + TSLogDebug("No Rules configured, falling back to default mapping rule"); } else { Rules* confp = static_cast<Rules*>(ih); http://git-wip-us.apache.org/repos/asf/trafficserver/blob/4e5cfae7/plugins/header_filter/lulu.h ---------------------------------------------------------------------- diff --git a/plugins/header_filter/lulu.h b/plugins/header_filter/lulu.h index 24cc165..80c73f5 100644 --- a/plugins/header_filter/lulu.h +++ b/plugins/header_filter/lulu.h @@ -47,8 +47,8 @@ #endif // Used for Debug etc. -static const char* PLUGIN_NAME = "header_filter"; -static const char* PLUGIN_NAME_DBG = "header_filter_dbg"; +#define PLUGIN_NAME "header_filter" +#include <ts/debug.h> // From google styleguide: http://google-styleguide.googlecode.com/svn/trunk/cppguide.xml #define DISALLOW_COPY_AND_ASSIGN(TypeName) \ http://git-wip-us.apache.org/repos/asf/trafficserver/blob/4e5cfae7/plugins/header_filter/rules.cc ---------------------------------------------------------------------- diff --git a/plugins/header_filter/rules.cc b/plugins/header_filter/rules.cc index 62c21cb..1257887 100644 --- a/plugins/header_filter/rules.cc +++ b/plugins/header_filter/rules.cc @@ -45,14 +45,14 @@ inline void add_header(TSMBuffer& reqp, TSMLoc& hdr_loc, const char* hdr, int hdr_len, const char* val, int val_len) { if (val_len <= 0) { - TSDebug(PLUGIN_NAME, "\tWould set header %s to an empty value, skipping", hdr); + TSLogDebug("\tWould set header %s to an empty value, skipping", hdr); } else { TSMLoc new_field; if (TS_SUCCESS == TSMimeHdrFieldCreateNamed(reqp, hdr_loc, hdr, hdr_len, &new_field)) { if (TS_SUCCESS == TSMimeHdrFieldValueStringInsert(reqp, hdr_loc, new_field, -1, val, val_len)) if (TS_SUCCESS == TSMimeHdrFieldAppend(reqp, hdr_loc, new_field)) - TSDebug(PLUGIN_NAME, "\tAdded header %s: %s", hdr, val); + TSLogDebug("\tAdded header %s: %s", hdr, val); TSHandleMLocRelease(reqp, hdr_loc, new_field); } } @@ -130,7 +130,7 @@ RulesEntry::execute(TSMBuffer& reqp, TSMLoc& hdr_loc) const nuke = false; first_set = false; if (TS_SUCCESS == TSMimeHdrFieldValueStringSet(reqp, hdr_loc, field, -1, _qualifier, _q_len)) - TSDebug(PLUGIN_NAME, "\tSet header: %s: %s", _header, _qualifier); + TSLogDebug("\tSet header: %s: %s", _header, _qualifier); } else { // Nuke all other "duplicates" of this header nuke = true; @@ -145,7 +145,7 @@ RulesEntry::execute(TSMBuffer& reqp, TSMLoc& hdr_loc) const nuke = !nuke; if (nuke) { if (TS_SUCCESS == TSMimeHdrFieldDestroy(reqp, hdr_loc, field)) - TSDebug(PLUGIN_NAME, "\tDeleting header %.*s", static_cast<int>(_h_len), _header); + TSLogDebug("\tDeleting header %.*s", static_cast<int>(_h_len), _header); } TSHandleMLocRelease(reqp, hdr_loc, field); field = tmp; @@ -158,7 +158,7 @@ RulesEntry::execute(TSMBuffer& reqp, TSMLoc& hdr_loc) const // Rules class implementations Rules::~Rules() { - TSDebug(PLUGIN_NAME_DBG, "Calling DTOR for Rules"); + TSLogDebug("Calling DTOR for Rules"); for (int i = 0; i < TS_HTTP_LAST_HOOK; ++i) delete _entries[i]; @@ -190,10 +190,10 @@ Rules::parse_file(const char* filename) // TODO: Should we support a 'default' prefix here for the rules? f.open(filename, std::ios::in); if (!f.is_open()) { - TSError("unable to open %s", filename); + TSLogError("unable to open %s", filename); return false; } - TSDebug(PLUGIN_NAME, "Parsing config file %s", filename); + TSLogDebug("Parsing config file %s", filename); while (!f.eof()) { bool inverse = false; int options = 0; @@ -277,18 +277,18 @@ Rules::parse_file(const char* filename) qualifier = line.substr(pos1+1, pos2-pos1-1); if (line[pos2+1] == 'i') options |= PCRE_CASELESS; - TSDebug(PLUGIN_NAME, "Adding '%s' to hook %d, type is %d, qualifier is %c %s (%c)", + TSLogDebug("Adding '%s' to hook %d, type is %d, qualifier is %c %s (%c)", word.c_str(), hook, type, inverse ? '!' : ' ', qualifier.c_str(), options & PCRE_CASELESS ? 'i' : ' '); add_entry(hook, word, qualifier, type, inverse, options); } else { - TSError("Missing trailing delimiter in qualifier"); + TSLogError("Missing trailing delimiter in qualifier"); } } else { - TSError("Missing leading delimiter in qualifier"); + TSLogError("Missing leading delimiter in qualifier"); } } else { // No qualifier, so we'll nuke this header for all values - TSDebug(PLUGIN_NAME, "Adding %s to hook %d (unqualified)", word.c_str(), hook); + TSLogDebug("Adding %s to hook %d (unqualified)", word.c_str(), hook); add_entry(hook, word); } } @@ -308,7 +308,7 @@ Rules::execute(TSMBuffer& reqp, TSMLoc& hdr_loc, const TSHttpHookID hook) const if (_entries[hook]) { RulesEntry* n = _entries[hook]; - TSDebug(PLUGIN_NAME, "Executing rules(s) for hook %d", hook); + TSLogDebug("Executing rules(s) for hook %d", hook); do { n->execute(reqp, hdr_loc); } while (NULL != (n = n->next())); http://git-wip-us.apache.org/repos/asf/trafficserver/blob/4e5cfae7/plugins/header_filter/rules.h ---------------------------------------------------------------------- diff --git a/plugins/header_filter/rules.h b/plugins/header_filter/rules.h index 70e3756..a6d6335 100644 --- a/plugins/header_filter/rules.h +++ b/plugins/header_filter/rules.h @@ -78,16 +78,16 @@ public: &erroffset, // for error offset NULL); // use default character tables if (!_rex) - TSError("header_filter: PCRE failed on %s at offset %d: %s\n", _qualifier, erroffset, error); + TSLogError("PCRE failed on %s at offset %d: %s\n", _qualifier, erroffset, error); } } - TSDebug(PLUGIN_NAME_DBG, "Calling CTOR for RulesEntry, header is %s, qualifier is %s", _header, _qualifier); + TSLogDebug("Calling CTOR for RulesEntry, header is %s, qualifier is %s", _header, _qualifier); } ~RulesEntry() { - TSDebug(PLUGIN_NAME_DBG, "Calling DTOR for RulesEntry"); + TSLogDebug("Calling DTOR for RulesEntry"); delete _next; // Potentially "deep" recursion, but should be OK. if (_header) TSfree(_header); @@ -127,7 +127,7 @@ class Rules public: Rules() { - TSDebug(PLUGIN_NAME_DBG, "Calling CTOR for Rules"); + TSLogDebug("Calling CTOR for Rules"); memset(_entries, 0, sizeof(_entries)); }
