From dcd0098823f6c7b03d2746fe1af41d091f3741a6 Mon Sep 17 00:00:00 2001 From: Markus Makela Date: Wed, 6 May 2015 17:33:02 +0300 Subject: [PATCH] Added stdout as an option for log output with the -l or --log command line option. --- .../Tutorials/Administration-Tutorial.md | 4 ++-- log_manager/log_manager.cc | 3 ++- server/core/gateway.c | 22 ++++++++++++++----- 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/Documentation/Tutorials/Administration-Tutorial.md b/Documentation/Tutorials/Administration-Tutorial.md index 929850eb5..0fb0051b5 100644 --- a/Documentation/Tutorials/Administration-Tutorial.md +++ b/Documentation/Tutorials/Administration-Tutorial.md @@ -48,9 +48,9 @@ Options may be passed to the MaxScale binary that alter this default behavior, t Use the filename passed as an argument instead of looking in $MAXSCALE_HOME/etc/MaxScale.cnf - -l| + -l|| --log= - Control where logs are written for the debug and trace level log messages. the default is to write these to a shared memory device, however using the -lfile or --log=file option will forced these to be written to regular files. + Control where logs are written for the debug and trace level log messages. the default is to write these to a shared memory device, however using the -lfile or --log=file option will forced these to be written to regular files. Using -lstdout or --log=stdout will use the standard output for all enabled logs. -v diff --git a/log_manager/log_manager.cc b/log_manager/log_manager.cc index 9358a9f97..3cb87935f 100644 --- a/log_manager/log_manager.cc +++ b/log_manager/log_manager.cc @@ -1686,7 +1686,8 @@ static bool fnames_conf_init( "-j ............(\"/tmp\")\n" "-l .......(no default)\n" "-m ............(argv[0])\n" - "-s .......(no default)\n"; + "-s .......(no default)\n" + "-o .......(write logs to stdout)\n"; /** * When init_started is set, clean must be done for it. diff --git a/server/core/gateway.c b/server/core/gateway.c index 7fda1017d..6c505b124 100644 --- a/server/core/gateway.c +++ b/server/core/gateway.c @@ -996,8 +996,8 @@ static void usage(void) " -c|--homedir=... relative|absolute MaxScale home directory\n" " -f|--config=... relative|absolute pathname of MaxScale configuration file\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" + " -l|--log=... log to file shared memory or stdout\n" + " -lfile, -lshm or -lstdout - defaults to shared memory\n" " -s|--syslog= log messages to syslog." " True or false - defaults to true\n" " -S|--maxscalelog= log messages to MaxScale log." @@ -1064,6 +1064,7 @@ int main(int argc, char **argv) void* log_flush_thr = NULL; int option_index; int logtofile = 0; /* Use shared memory or file */ + int logtostdout = 0; /* Use stdout for log output */ int syslog_enabled = 1; /** Log to syslog */ int maxscalelog_enabled = 1; /** Log with MaxScale */ ssize_t log_flush_timeout_ms = 0; @@ -1198,6 +1199,8 @@ int main(int argc, char **argv) logtofile = 1; else if (strncasecmp(optarg, "shm", PATH_MAX) == 0) logtofile = 0; + else if (strncasecmp(optarg, "stdout", PATH_MAX) == 0) + logtostdout = 1; else { char* logerr = "Configuration file argument " @@ -1575,7 +1578,7 @@ int main(int argc, char **argv) */ { char buf[1024]; - char *argv[8]; + char *argv[9]; bool succp; /** Set log directory under $MAXSCALE_HOME/log */ sprintf(buf, "%s/log", home_dir); @@ -1605,8 +1608,17 @@ int main(int argc, char **argv) } logmanager_enable_syslog(syslog_enabled); logmanager_enable_maxscalelog(maxscalelog_enabled); - - if (logtofile) + if (logtostdout) + { + argv[3] = "-s"; /*< store to shared memory */ + argv[4] = "LOGFILE_DEBUG,LOGFILE_TRACE"; /*< to shm */ + argv[5] = "-l"; /*< write to syslog */ + argv[6] = "LOGFILE_MESSAGE,LOGFILE_ERROR"; /*< to syslog */ + argv[7] = "-o"; + argv[8] = NULL; + succp = skygw_logmanager_init(8, argv); + } + else if (logtofile) { argv[3] = "-l"; /*< write to syslog */ /** Logs that should be syslogged */