Allow logging to shared memory to be enabled in config file.
Earlier, by default, the error and message logfiles were written to the filesystem and trace and debug logfiles to shared memory. Now, with just one log-file the default must be the file-system. However, if info and debug messages are logged, then the filesystem will become a bottle-neck. A reasonable approach is then as follows (in the config file) syslog=true maxlog=false log_to_shm=true With this set, the maxlog file will be created to shared memory, but nothing will be written to it, since it is disabled. However, if there is a need to investigate something, then a dba can from maxadmin turn on maxlog logging and also enable info and debug messages. That is, it will be possible to enable debugging output without restarting maxscale. Incidentally, the way the config file and command line arguments are handled should be rewritten. Currently, it is a mess.
This commit is contained in:
@ -174,6 +174,10 @@ static struct option long_options[] = {
|
||||
{"log_augmentation", required_argument, 0, 'G'},
|
||||
{0, 0, 0, 0}
|
||||
};
|
||||
static bool syslog_configured = false;
|
||||
static bool maxlog_configured = false;
|
||||
static bool log_to_shm_configured = false;
|
||||
|
||||
static int cnf_preparser(void* data, const char* section, const char* name, const char* value);
|
||||
static void log_flush_shutdown(void);
|
||||
static void log_flush_cb(void* arg);
|
||||
@ -1032,9 +1036,9 @@ int main(int argc, char **argv)
|
||||
char* tmp_path;
|
||||
char* tmp_var;
|
||||
int option_index;
|
||||
mxs_log_target_t log_target = MXS_LOG_TARGET_FS;
|
||||
int *syslog_enabled = &config_get_global_options()->syslog; /** Log to syslog */
|
||||
int *maxlog_enabled = &config_get_global_options()->maxlog; /** Log with MaxScale */
|
||||
int *log_to_shm = &config_get_global_options()->log_to_shm; /** Log to shared memory */
|
||||
ssize_t log_flush_timeout_ms = 0;
|
||||
sigset_t sigset;
|
||||
sigset_t sigpipe_mask;
|
||||
@ -1043,6 +1047,7 @@ int main(int argc, char **argv)
|
||||
|
||||
*syslog_enabled = 1;
|
||||
*maxlog_enabled = 1;
|
||||
*log_to_shm = 0;
|
||||
|
||||
sigemptyset(&sigpipe_mask);
|
||||
sigaddset(&sigpipe_mask, SIGPIPE);
|
||||
@ -1121,9 +1126,15 @@ int main(int argc, char **argv)
|
||||
|
||||
case 'l':
|
||||
if (strncasecmp(optarg, "file", PATH_MAX) == 0)
|
||||
log_target = MXS_LOG_TARGET_FS;
|
||||
{
|
||||
*log_to_shm = false;
|
||||
log_to_shm_configured = true;
|
||||
}
|
||||
else if (strncasecmp(optarg, "shm", PATH_MAX) == 0)
|
||||
log_target = MXS_LOG_TARGET_SHMEM;
|
||||
{
|
||||
*log_to_shm = true;
|
||||
log_to_shm_configured = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
char* logerr = "Configuration file argument "
|
||||
@ -1210,11 +1221,15 @@ int main(int argc, char **argv)
|
||||
{
|
||||
tok++;
|
||||
if (tok)
|
||||
{
|
||||
*maxlog_enabled = config_truth_value(tok);
|
||||
maxlog_configured = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
*maxlog_enabled = config_truth_value(optarg);
|
||||
maxlog_configured = true;
|
||||
}
|
||||
}
|
||||
break;
|
||||
@ -1225,11 +1240,15 @@ int main(int argc, char **argv)
|
||||
{
|
||||
tok++;
|
||||
if (tok)
|
||||
{
|
||||
*syslog_enabled = config_truth_value(tok);
|
||||
syslog_configured = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
*syslog_enabled = config_truth_value(optarg);
|
||||
syslog_configured = true;
|
||||
}
|
||||
}
|
||||
break;
|
||||
@ -1674,6 +1693,8 @@ int main(int argc, char **argv)
|
||||
mxs_log_set_syslog_enabled(*syslog_enabled);
|
||||
mxs_log_set_maxlog_enabled(*maxlog_enabled);
|
||||
|
||||
mxs_log_target_t log_target = *log_to_shm ? MXS_LOG_TARGET_SHMEM : MXS_LOG_TARGET_FS;
|
||||
|
||||
succp = mxs_log_init(NULL, get_logdir(), log_target);
|
||||
|
||||
if (!succp)
|
||||
@ -2376,16 +2397,29 @@ static int cnf_preparser(void* data, const char* section, const char* name, cons
|
||||
}
|
||||
else if (strcmp(name, "syslog") == 0)
|
||||
{
|
||||
cnf->syslog = config_truth_value((char*)value);
|
||||
if (!syslog_configured)
|
||||
{
|
||||
cnf->syslog = config_truth_value((char*)value);
|
||||
}
|
||||
}
|
||||
else if (strcmp(name, "maxlog") == 0)
|
||||
{
|
||||
cnf->maxlog = config_truth_value((char*)value);
|
||||
if (!maxlog_configured)
|
||||
{
|
||||
cnf->maxlog = config_truth_value((char*)value);
|
||||
}
|
||||
}
|
||||
else if (strcmp(name, "log_augmentation") == 0)
|
||||
{
|
||||
set_log_augmentation(value);
|
||||
}
|
||||
else if (strcmp(name, "log_to_shm") == 0)
|
||||
{
|
||||
if (!log_to_shm_configured)
|
||||
{
|
||||
cnf->log_to_shm = config_truth_value((char*)value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
|
||||
Reference in New Issue
Block a user