Added option to disable logging to MaxScale's log files.

This commit is contained in:
Markus Makela 2015-03-09 19:38:37 +02:00
parent 65465b11f5
commit 1b91f776a3
3 changed files with 54 additions and 3 deletions

View File

@ -53,6 +53,7 @@ static simple_mutex_t msg_mutex;
#endif
static int highprec = 0;
static int do_syslog = 1;
static int do_maxscalelog = 1;
/**
* Variable holding the enabled logfiles information.
@ -751,10 +752,17 @@ static int logmanager_write_log(
}
#endif
/** Book space for log string from buffer */
if(do_maxscalelog)
{
wp = blockbuf_get_writepos(&bb,
id,
safe_str_len,
flush);
}
else
{
wp = (char*)malloc(sizeof(char)*(timestamp_len-sizeof(char)+cmplen+str_len + 1));
}
#if defined (SS_LOG_DEBUG)
@ -822,8 +830,15 @@ static int logmanager_write_log(
wp[safe_str_len-2]=' ';
}
wp[safe_str_len-1] = '\n';
blockbuf_unregister(bb);
if(do_maxscalelog)
{
blockbuf_unregister(bb);
}
else
{
free(wp);
}
/**
* disable because cross-blockbuffer locking either causes deadlock
* or run out of memory blocks.
@ -3112,4 +3127,13 @@ void skygw_set_highp(int val)
void logmanager_enable_syslog(int val)
{
do_syslog = val;
}
/**
* Toggle syslog logging
* @param val 0 for disabled, 1 for enabled
*/
void logmanager_enable_maxscalelog(int val)
{
do_maxscalelog = val;
}

View File

@ -121,6 +121,8 @@ int skygw_log_disable(logfile_id_t id);
void skygw_log_sync_all(void);
void skygw_set_highp(int);
void logmanager_enable_syslog(int);
void logmanager_enable_maxscalelog(int);
EXTERN_C_BLOCK_END
const char* get_trace_prefix_default(void);

View File

@ -151,6 +151,7 @@ static struct option long_options[] = {
{"nodaemon", no_argument, 0, 'd'},
{"log", required_argument, 0, 'l'},
{"syslog", required_argument, 0, 's'},
{"maxscalelog", required_argument, 0, 'S'},
{"version", no_argument, 0, 'v'},
{"help", no_argument, 0, '?'},
{0, 0, 0, 0}
@ -998,6 +999,8 @@ static void usage(void)
" -lfile or -lshm - defaults to shared memory\n"
" -s|--syslog= log messages to syslog"
" true or false - defaults to true"
" -S|--maxscalelog= log messages to MaxScale log"
" true or false - defaults to true"
" -v|--version print version info and exit\n"
" -?|--help show this help\n"
, progname);
@ -1061,6 +1064,7 @@ int main(int argc, char **argv)
int option_index;
int logtofile = 0; /* Use shared memory or file */
int syslog_enabled = 1; /** Log to syslog */
int maxscalelog_enabled = 1; /** Log with MaxScale */
ssize_t log_flush_timeout_ms = 0;
sigset_t sigset;
sigset_t sigpipe_mask;
@ -1100,7 +1104,7 @@ int main(int argc, char **argv)
goto return_main;
}
}
while ((opt = getopt_long(argc, argv, "dc:f:l:vs:?",
while ((opt = getopt_long(argc, argv, "dc:f:l:vs:S:?",
long_options, &option_index)) != -1)
{
bool succp = true;
@ -1205,6 +1209,17 @@ int main(int argc, char **argv)
succp = false;
}
break;
case 'S':
if(strstr(optarg,"="))
{
strtok(optarg,"= ");
maxscalelog_enabled = config_truth_value(strtok(NULL,"= "));
}
else
{
maxscalelog_enabled = config_truth_value(optarg);
}
break;
case 's':
if(strstr(optarg,"="))
{
@ -1578,8 +1593,18 @@ int main(int argc, char **argv)
argv[1] = "-j";
argv[2] = buf;
logmanager_enable_syslog(syslog_enabled);
if(!syslog_enabled)
{
printf("Syslog logging is disabled.\n");
}
if(!maxscalelog_enabled)
{
printf("MaxScale logging is disabled.\n");
}
logmanager_enable_syslog(syslog_enabled);
logmanager_enable_maxscalelog(maxscalelog_enabled);
if (logtofile)
{
argv[3] = "-l"; /*< write to syslog */