Skip to content

Commit

Permalink
TS-2424: set diags log file for each caller
Browse files Browse the repository at this point in the history
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
jpeach committed Dec 10, 2013
1 parent e510c58 commit 4b94cdf
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 27 deletions.
5 changes: 3 additions & 2 deletions mgmt/Main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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 ";

Expand Down Expand Up @@ -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 ";
Expand Down
5 changes: 3 additions & 2 deletions proxy/Main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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"))
Expand Down Expand Up @@ -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 ";
Expand Down
14 changes: 12 additions & 2 deletions proxy/logging/LogStandalone.cc
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@
// Needs LibRecordsConfigInit()
#include "RecordsConfig.h"

#define LOG_FILENAME_SIZE 255

class HttpBodyFactory;

// globals the rest of the system depends on
Expand Down Expand Up @@ -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);
Expand All @@ -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;
}
Expand All @@ -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
//
Expand Down
5 changes: 4 additions & 1 deletion proxy/sac.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
//
Expand Down
20 changes: 4 additions & 16 deletions proxy/shared/DiagsConfig.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"


Expand Down Expand Up @@ -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;
Expand All @@ -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;
}
Expand All @@ -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");
Expand All @@ -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),
Expand Down
13 changes: 9 additions & 4 deletions proxy/shared/DiagsConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};


Expand Down

0 comments on commit 4b94cdf

Please sign in to comment.