TS-2424: set diags log file for each caller Since DiagsConfig.cc is built into a static library, we can't rely on the preprocessor to determine what the diagnostic log file should be. Add a filename to the constructor so that each usage uses an explicit name.
Project: http://git-wip-us.apache.org/repos/asf/trafficserver/repo Commit: http://git-wip-us.apache.org/repos/asf/trafficserver/commit/4b94cdfd Tree: http://git-wip-us.apache.org/repos/asf/trafficserver/tree/4b94cdfd Diff: http://git-wip-us.apache.org/repos/asf/trafficserver/diff/4b94cdfd Branch: refs/heads/5.0.x Commit: 4b94cdfd7942595fc461344f1bae834672e84502 Parents: e510c58 Author: James Peach <jpe...@apache.org> Authored: Tue Dec 10 09:04:18 2013 -0800 Committer: James Peach <jpe...@apache.org> Committed: Tue Dec 10 11:22:15 2013 -0800 ---------------------------------------------------------------------- mgmt/Main.cc | 5 +++-- proxy/Main.cc | 5 +++-- proxy/logging/LogStandalone.cc | 14 ++++++++++++-- proxy/sac.cc | 5 ++++- proxy/shared/DiagsConfig.cc | 20 ++++---------------- proxy/shared/DiagsConfig.h | 13 +++++++++---- 6 files changed, 35 insertions(+), 27 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/trafficserver/blob/4b94cdfd/mgmt/Main.cc ---------------------------------------------------------------------- diff --git a/mgmt/Main.cc b/mgmt/Main.cc index 0219e68..2452f16 100644 --- a/mgmt/Main.cc +++ b/mgmt/Main.cc @@ -59,6 +59,7 @@ #include <grp.h> #define FD_THROTTLE_HEADROOM (128 + 64) // TODO: consolidate with THROTTLE_FD_HEADROOM +#define DIAGS_LOG_FILENAME "manager.log" #if defined(freebsd) extern "C" int getpwnam_r(const char *name, struct passwd *result, char *buffer, size_t buflen, struct passwd **resptr); @@ -520,7 +521,7 @@ main(int argc, char **argv) // Bootstrap the Diags facility so that we can use it while starting // up the manager - diagsConfig = NEW(new DiagsConfig(debug_tags, action_tags, false)); + diagsConfig = NEW(new DiagsConfig(DIAGS_LOG_FILENAME, debug_tags, action_tags, false)); diags = diagsConfig->diags; diags->prefix_str = "Manager "; @@ -570,7 +571,7 @@ main(int argc, char **argv) } // INKqa11968: need to set up callbacks and diags data structures // using configuration in records.config - diagsConfig = NEW(new DiagsConfig(debug_tags, action_tags, true)); + diagsConfig = NEW(new DiagsConfig(DIAGS_LOG_FILENAME, debug_tags, action_tags, true)); diags = diagsConfig->diags; RecSetDiags(diags); diags->prefix_str = "Manager "; http://git-wip-us.apache.org/repos/asf/trafficserver/blob/4b94cdfd/proxy/Main.cc ---------------------------------------------------------------------- diff --git a/proxy/Main.cc b/proxy/Main.cc index bc7c2d5..b03465b 100644 --- a/proxy/Main.cc +++ b/proxy/Main.cc @@ -112,6 +112,7 @@ extern "C" int plock(int); #endif #define DEFAULT_REMOTE_MANAGEMENT_FLAG 0 +#define DIAGS_LOG_FILENAME "diags.log" static const long MAX_LOGIN = sysconf(_SC_LOGIN_NAME_MAX) <= 0 ? _POSIX_LOGIN_NAME_MAX : sysconf(_SC_LOGIN_NAME_MAX); @@ -1285,7 +1286,7 @@ main(int /* argc ATS_UNUSED */, char **argv) // re-start Diag completely) because at initialize, TM only has 1 thread. // In TS, some threads have already created, so if we delete Diag and // re-start it again, TS will crash. - diagsConfig = NEW(new DiagsConfig(error_tags, action_tags, false)); + diagsConfig = NEW(new DiagsConfig(DIAGS_LOG_FILENAME, error_tags, action_tags, false)); diags = diagsConfig->diags; diags->prefix_str = "Server "; if (is_debug_tag_set("diags")) @@ -1347,7 +1348,7 @@ main(int /* argc ATS_UNUSED */, char **argv) RecDebugOff(); delete(diagsConfig); } - diagsConfig = NEW(new DiagsConfig(error_tags, action_tags, true)); + diagsConfig = NEW(new DiagsConfig(DIAGS_LOG_FILENAME, error_tags, action_tags, true)); diags = diagsConfig->diags; RecSetDiags(diags); diags->prefix_str = "Server "; http://git-wip-us.apache.org/repos/asf/trafficserver/blob/4b94cdfd/proxy/logging/LogStandalone.cc ---------------------------------------------------------------------- diff --git a/proxy/logging/LogStandalone.cc b/proxy/logging/LogStandalone.cc index 5d79f80..931a254 100644 --- a/proxy/logging/LogStandalone.cc +++ b/proxy/logging/LogStandalone.cc @@ -42,6 +42,8 @@ // Needs LibRecordsConfigInit() #include "RecordsConfig.h" +#define LOG_FILENAME_SIZE 255 + class HttpBodyFactory; // globals the rest of the system depends on @@ -196,11 +198,16 @@ check_lockfile() void init_log_standalone(const char *pgm_name, bool one_copy) { + char logfile[LOG_FILENAME_SIZE]; + // ensure that only one copy of the sac is running // if (one_copy) { check_lockfile(); } + + snprintf(logfile, sizeof(logfile), "%s.log", pgm_name); + // set stdin/stdout to be unbuffered // setbuf(stdin, NULL); @@ -210,7 +217,7 @@ init_log_standalone(const char *pgm_name, bool one_copy) init_system(); initialize_process_manager(); - diagsConfig = NEW(new DiagsConfig(error_tags, action_tags)); + diagsConfig = NEW(new DiagsConfig(logfile, error_tags, action_tags)); diags = diagsConfig->diags; diags_init = 1; } @@ -232,11 +239,14 @@ init_log_standalone(const char *pgm_name, bool one_copy) void init_log_standalone_basic(const char *pgm_name) { + char logfile[LOG_FILENAME_SIZE]; + + snprintf(logfile, sizeof(logfile), "%s.log", pgm_name); openlog(pgm_name, LOG_PID | LOG_NDELAY | LOG_NOWAIT, LOG_DAEMON); init_system(); const bool use_records = false; - diagsConfig = NEW(new DiagsConfig(error_tags, action_tags, use_records)); + diagsConfig = NEW(new DiagsConfig(logfile, error_tags, action_tags, use_records)); diags = diagsConfig->diags; // set stdin/stdout to be unbuffered // http://git-wip-us.apache.org/repos/asf/trafficserver/blob/4b94cdfd/proxy/sac.cc ---------------------------------------------------------------------- diff --git a/proxy/sac.cc b/proxy/sac.cc index a9e4a9b..661b3cf 100644 --- a/proxy/sac.cc +++ b/proxy/sac.cc @@ -46,6 +46,8 @@ #include "DiagsConfig.h" #include "I_Machine.h" +#define DIAGS_LOG_FILENAME "collector.log" + // sac-specific command-line flags // static int version_flag = 0; @@ -90,8 +92,9 @@ main(int /* argc ATS_UNUSED */, char *argv[]) _exit(0); } - diagsConfig = NEW(new DiagsConfig(error_tags, action_tags, false)); + diagsConfig = NEW(new DiagsConfig(DIAGS_LOG_FILENAME, error_tags, action_tags, false)); diags = diagsConfig->diags; + diags->prefix_str = "Collector "; // initialize this application for standalone logging operation // http://git-wip-us.apache.org/repos/asf/trafficserver/blob/4b94cdfd/proxy/shared/DiagsConfig.cc ---------------------------------------------------------------------- diff --git a/proxy/shared/DiagsConfig.cc b/proxy/shared/DiagsConfig.cc index 3cb6a3d..6576ff9 100644 --- a/proxy/shared/DiagsConfig.cc +++ b/proxy/shared/DiagsConfig.cc @@ -24,18 +24,6 @@ #include "libts.h" #include "I_Layout.h" #include "DiagsConfig.h" -#ifdef LOCAL_MANAGER - -#include "mgmt/Main.h" -#define DIAGS_LOG_FILE "manager.log" - -#else -#include "proxy/Main.h" -#include "ProxyConfig.h" -#define DIAGS_LOG_FILE "diags.log" - -#endif - #include "P_RecCore.h" @@ -285,7 +273,7 @@ DiagsConfig::RegisterDiagConfig() } -DiagsConfig::DiagsConfig(char *bdt, char *bat, bool use_records) +DiagsConfig::DiagsConfig(const char * filename, const char * tags, const char * actions, bool use_records) { char diags_logpath[PATH_NAME_MAX + 1]; xptr<char> logpath; @@ -301,7 +289,7 @@ DiagsConfig::DiagsConfig(char *bdt, char *bat, bool use_records) //////////////////////////////////////////////////////////////////// if (!use_records) { - diags = NEW(new Diags(bdt, bat, NULL)); + diags = NEW(new Diags(tags, actions, NULL)); config_diags_norecords(); return; } @@ -317,7 +305,7 @@ DiagsConfig::DiagsConfig(char *bdt, char *bat, bool use_records) _exit(1); } - ink_filepath_make(diags_logpath, sizeof(diags_logpath), logpath, DIAGS_LOG_FILE); + ink_filepath_make(diags_logpath, sizeof(diags_logpath), logpath, filename); // open write append // diags_log_fp = fopen(diags_logpath,"w"); @@ -331,7 +319,7 @@ DiagsConfig::DiagsConfig(char *bdt, char *bat, bool use_records) } } - diags = NEW(new Diags(bdt, bat, diags_log_fp)); + diags = NEW(new Diags(tags, actions, diags_log_fp)); if (diags_log_fp == NULL) { diags->print(NULL, DTA(DL_Warning), http://git-wip-us.apache.org/repos/asf/trafficserver/blob/4b94cdfd/proxy/shared/DiagsConfig.h ---------------------------------------------------------------------- diff --git a/proxy/shared/DiagsConfig.h b/proxy/shared/DiagsConfig.h index b5a69b9..730d134 100644 --- a/proxy/shared/DiagsConfig.h +++ b/proxy/shared/DiagsConfig.h @@ -27,17 +27,22 @@ struct DiagsConfig { - bool callbacks_established; - FILE *diags_log_fp; - Diags *diags; void reconfigure_diags(); void config_diags_norecords(); void parse_output_string(char *s, DiagsModeOutput * o); void RegisterDiagConfig(); void register_diags_callbacks(); - DiagsConfig(char *bdt, char *bat, bool use_records = true); + + DiagsConfig(const char * filename, const char * tags, const char * actions, bool use_records = true); ~DiagsConfig(); + +private: + bool callbacks_established; + FILE *diags_log_fp; + +public: + Diags *diags; };