diff --git a/include/maxscale/log_manager.h b/include/maxscale/log_manager.h index e845d3b77..02c1b4c71 100644 --- a/include/maxscale/log_manager.h +++ b/include/maxscale/log_manager.h @@ -106,6 +106,7 @@ void mxs_log_set_maxlog_enabled(bool enabled); void mxs_log_set_highprecision_enabled(bool enabled); void mxs_log_set_augmentation(int bits); void mxs_log_set_throttling(const MXS_LOG_THROTTLING* throttling); +void mxs_log_redirect_stdout(bool redirect); void mxs_log_get_throttling(MXS_LOG_THROTTLING* throttling); json_t* mxs_logs_to_json(const char* host); diff --git a/server/core/gateway.cc b/server/core/gateway.cc index 06ee47d16..3482315fb 100644 --- a/server/core/gateway.cc +++ b/server/core/gateway.cc @@ -1985,6 +1985,11 @@ int main(int argc, char **argv) log_target = MXS_LOG_TARGET_SHMEM; } + if (!to_stdout && daemon_mode) + { + mxs_log_redirect_stdout(true); + } + succp = mxs_log_init(NULL, get_logdir(), log_target); if (!succp) diff --git a/server/core/log_manager.cc b/server/core/log_manager.cc index 893971e53..d625235a4 100644 --- a/server/core/log_manager.cc +++ b/server/core/log_manager.cc @@ -160,6 +160,7 @@ static bool flushall_flag; static bool flushall_started_flag; static bool flushall_done_flag; static HASHTABLE* message_stats; +static bool redirect_stdout = false; /** This is used to detect if the initialization of the log manager has failed * and that it isn't initialized again after a failure has occurred. */ @@ -572,9 +573,12 @@ static bool logmanager_init_nomutex(const char* ident, succ = true; lm->lm_enabled = true; - // Redirect stdout and stderr to the log file - freopen(lm->lm_logfile.lf_full_file_name, "a", stdout); - freopen(lm->lm_logfile.lf_full_file_name, "a", stderr); + if (redirect_stdout) + { + // Redirect stdout and stderr to the log file + freopen(lm->lm_logfile.lf_full_file_name, "a", stdout); + freopen(lm->lm_logfile.lf_full_file_name, "a", stderr); + } return_succ: if (err != 0) @@ -2159,7 +2163,7 @@ static bool thr_flush_file(logmanager_t *lm, filewriter_t *fwr) LOG_ERROR("MaxScale Log: Error, could not re-open log file %s.\n", lf->lf_full_file_name); } - else + else if (redirect_stdout) { // Redirect stdout and stderr to the new log file freopen(lf->lf_full_file_name, "a", stdout); @@ -3131,3 +3135,8 @@ json_t* mxs_logs_to_json(const char* host) return mxs_json_resource(host, MXS_JSON_API_LOGS, data); } + +void mxs_log_redirect_stdout(bool redirect) +{ + redirect_stdout = redirect; +}