Permalink
Browse files

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.
  • Loading branch information...
1 parent e510c58 commit 4b94cdfd7942595fc461344f1bae834672e84502 @jpeach jpeach committed Dec 10, 2013
Showing with 35 additions and 27 deletions.
  1. +3 −2 mgmt/Main.cc
  2. +3 −2 proxy/Main.cc
  3. +12 −2 proxy/logging/LogStandalone.cc
  4. +4 −1 proxy/sac.cc
  5. +4 −16 proxy/shared/DiagsConfig.cc
  6. +9 −4 proxy/shared/DiagsConfig.h
View
@@ -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 ";
View
@@ -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 ";
@@ -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
//
View
@@ -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
//
@@ -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),
View
@@ -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;
};

0 comments on commit 4b94cdf

Please sign in to comment.