bug 506 - add command line option (-l --log=file) to log to file or
shared memory. Only affects trace and debug logs.
This commit is contained in:
@ -137,6 +137,7 @@ static struct option long_options[] = {
|
|||||||
{"homedir", required_argument, 0, 'c'},
|
{"homedir", required_argument, 0, 'c'},
|
||||||
{"config", required_argument, 0, 'f'},
|
{"config", required_argument, 0, 'f'},
|
||||||
{"nodeamon", required_argument, 0, 'd'},
|
{"nodeamon", required_argument, 0, 'd'},
|
||||||
|
{"log", required_argument, 0, 'l'},
|
||||||
{"version", no_argument, 0, 'v'},
|
{"version", no_argument, 0, 'v'},
|
||||||
{"help", no_argument, 0, '?'},
|
{"help", no_argument, 0, '?'},
|
||||||
{0, 0, 0, 0}
|
{0, 0, 0, 0}
|
||||||
@ -897,6 +898,8 @@ static void usage(void)
|
|||||||
" -c|--homedir=... relative|absolute MaxScale home directory\n"
|
" -c|--homedir=... relative|absolute MaxScale home directory\n"
|
||||||
" -f|--config=... relative|absolute pathname of MaxScale configuration file\n"
|
" -f|--config=... relative|absolute pathname of MaxScale configuration file\n"
|
||||||
" (default: $MAXSCALE_HOME/etc/MaxScale.cnf)\n"
|
" (default: $MAXSCALE_HOME/etc/MaxScale.cnf)\n"
|
||||||
|
" -l|--log=... log to file or shared memory\n"
|
||||||
|
" -lfile or -lshm - defaults to shared memory\n"
|
||||||
" -v|--version print version info and exit\n"
|
" -v|--version print version info and exit\n"
|
||||||
" -?|--help show this help\n"
|
" -?|--help show this help\n"
|
||||||
, progname);
|
, progname);
|
||||||
@ -957,6 +960,7 @@ int main(int argc, char **argv)
|
|||||||
char* cnf_file_arg = NULL; /*< conf filename from cmd-line arg */
|
char* cnf_file_arg = NULL; /*< conf filename from cmd-line arg */
|
||||||
void* log_flush_thr = NULL;
|
void* log_flush_thr = NULL;
|
||||||
int option_index;
|
int option_index;
|
||||||
|
int logtofile = 0; /* Use shared memory or file */
|
||||||
ssize_t log_flush_timeout_ms = 0;
|
ssize_t log_flush_timeout_ms = 0;
|
||||||
sigset_t sigset;
|
sigset_t sigset;
|
||||||
sigset_t sigpipe_mask;
|
sigset_t sigpipe_mask;
|
||||||
@ -996,7 +1000,7 @@ int main(int argc, char **argv)
|
|||||||
goto return_main;
|
goto return_main;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
while ((opt = getopt_long(argc, argv, "dc:f:v?",
|
while ((opt = getopt_long(argc, argv, "dc:f:l:v?",
|
||||||
long_options, &option_index)) != -1)
|
long_options, &option_index)) != -1)
|
||||||
{
|
{
|
||||||
bool succp = true;
|
bool succp = true;
|
||||||
@ -1083,6 +1087,24 @@ int main(int argc, char **argv)
|
|||||||
rc = EXIT_SUCCESS;
|
rc = EXIT_SUCCESS;
|
||||||
goto return_main;
|
goto return_main;
|
||||||
|
|
||||||
|
case 'l':
|
||||||
|
if (strncasecmp(optarg, "file") == 0)
|
||||||
|
logtofile = 1;
|
||||||
|
else if (strncasecmp(optarg, "shm") == 0)
|
||||||
|
logtofile = 0;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
char* logerr = "Configuration file argument "
|
||||||
|
"identifier \'-l\' was specified but "
|
||||||
|
"the argument didn't specify\n a valid "
|
||||||
|
"configuration file or the argument "
|
||||||
|
"was missing.";
|
||||||
|
print_log_n_stderr(true, true, logerr, logerr, 0);
|
||||||
|
usage();
|
||||||
|
succp = false;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
case '?':
|
case '?':
|
||||||
usage();
|
usage();
|
||||||
rc = EXIT_SUCCESS;
|
rc = EXIT_SUCCESS;
|
||||||
@ -1371,6 +1393,16 @@ int main(int argc, char **argv)
|
|||||||
argv[0] = "MaxScale";
|
argv[0] = "MaxScale";
|
||||||
argv[1] = "-j";
|
argv[1] = "-j";
|
||||||
argv[2] = buf;
|
argv[2] = buf;
|
||||||
|
if (logtofile)
|
||||||
|
{
|
||||||
|
argv[3] = "-l"; /*< write to syslog */
|
||||||
|
argv[4] = "LOGFILE_MESSAGE,LOGFILE_ERROR"
|
||||||
|
"LOGFILE_DEBUG,LOGFILE_TRACE";
|
||||||
|
argv[5] = NULL;
|
||||||
|
skygw_logmanager_init(5, argv);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
argv[3] = "-s"; /*< store to shared memory */
|
argv[3] = "-s"; /*< store to shared memory */
|
||||||
argv[4] = "LOGFILE_DEBUG,LOGFILE_TRACE"; /*< ..these logs to shm */
|
argv[4] = "LOGFILE_DEBUG,LOGFILE_TRACE"; /*< ..these logs to shm */
|
||||||
argv[5] = "-l"; /*< write to syslog */
|
argv[5] = "-l"; /*< write to syslog */
|
||||||
@ -1378,6 +1410,7 @@ int main(int argc, char **argv)
|
|||||||
argv[7] = NULL;
|
argv[7] = NULL;
|
||||||
skygw_logmanager_init(7, argv);
|
skygw_logmanager_init(7, argv);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*<
|
/*<
|
||||||
* Resolve the full pathname for configuration file and check for
|
* Resolve the full pathname for configuration file and check for
|
||||||
|
|||||||
Reference in New Issue
Block a user