Added a command line option for syslog logging.

This commit is contained in:
Markus Makela 2015-03-05 12:37:39 +02:00
parent d6da4c7501
commit 1ff0756044
3 changed files with 46 additions and 3 deletions

View File

@ -52,6 +52,8 @@ static int prevval;
static simple_mutex_t msg_mutex;
#endif
static int highprec = 0;
static int do_syslog = 1;
/**
* Variable holding the enabled logfiles information.
* Used from log users to check enabled logs prior calling
@ -392,7 +394,13 @@ static bool logmanager_init_nomutex(
fw = &lm->lm_filewriter;
fn->fn_state = UNINIT;
fw->fwr_state = UNINIT;
if(!do_syslog)
{
free(syslog_id_str);
syslog_id_str = NULL;
}
/** Initialize configuration including log file naming info */
if (!fnames_conf_init(fn, argc, argv))
{
@ -1703,11 +1711,14 @@ static bool fnames_conf_init(
case 'l':
/** record list of log file ids for syslogged */
if(do_syslog)
{
if (syslog_id_str != NULL)
{
free (syslog_id_str);
}
syslog_id_str = optarg;
}
break;
case 'm':
@ -1720,6 +1731,7 @@ static bool fnames_conf_init(
case 's':
/** record list of log file ids for later use */
if(do_syslog)
shmem_id_str = optarg;
break;
case 'h':
@ -3083,7 +3095,21 @@ void skygw_log_sync_all(void)
skygw_message_wait(lm->lm_clientmes);
}
/**
* Toggle high precision logging
* @param val 0 for disabled, 1 for enabled
*/
void skygw_set_highp(int val)
{
highprec = val;
}
/**
* Toggle syslog logging
* @param val 0 for disabled, 1 for enabled
*/
void logmanager_enable_syslog(int val)
{
do_syslog = val;
}

View File

@ -120,6 +120,7 @@ int skygw_log_enable(logfile_id_t id);
int skygw_log_disable(logfile_id_t id);
void skygw_log_sync_all(void);
void skygw_set_highp(int);
void logmanager_enable_syslog(int);
EXTERN_C_BLOCK_END
const char* get_trace_prefix_default(void);

View File

@ -150,6 +150,7 @@ static struct option long_options[] = {
{"config", required_argument, 0, 'f'},
{"nodaemon", no_argument, 0, 'd'},
{"log", required_argument, 0, 'l'},
{"syslog", required_argument, 0, 's'},
{"version", no_argument, 0, 'v'},
{"help", no_argument, 0, '?'},
{0, 0, 0, 0}
@ -995,6 +996,8 @@ static void usage(void)
" (default: $MAXSCALE_HOME/etc/MaxScale.cnf)\n"
" -l|--log=... log to file or shared memory\n"
" -lfile or -lshm - defaults to shared memory\n"
" -s|--syslog= log messages to syslog"
" true or false - defaults to true"
" -v|--version print version info and exit\n"
" -?|--help show this help\n"
, progname);
@ -1057,6 +1060,7 @@ int main(int argc, char **argv)
void* log_flush_thr = NULL;
int option_index;
int logtofile = 0; /* Use shared memory or file */
int syslog_enabled = 1; /** Log to syslog */
ssize_t log_flush_timeout_ms = 0;
sigset_t sigset;
sigset_t sigpipe_mask;
@ -1096,7 +1100,7 @@ int main(int argc, char **argv)
goto return_main;
}
}
while ((opt = getopt_long(argc, argv, "dc:f:l:v?",
while ((opt = getopt_long(argc, argv, "dc:f:l:vs:?",
long_options, &option_index)) != -1)
{
bool succp = true;
@ -1201,7 +1205,17 @@ int main(int argc, char **argv)
succp = false;
}
break;
case 's':
if(strstr(optarg,"="))
{
strtok(optarg,"= ");
syslog_enabled = config_truth_value(strtok(NULL,"= "));
}
else
{
syslog_enabled = config_truth_value(optarg);
}
break;
case '?':
usage();
rc = EXIT_SUCCESS;
@ -1563,6 +1577,8 @@ int main(int argc, char **argv)
argv[0] = "MaxScale";
argv[1] = "-j";
argv[2] = buf;
logmanager_enable_syslog(syslog_enabled);
if (logtofile)
{