diff --git a/log_manager/log_manager.cc b/log_manager/log_manager.cc index 7ae102a0d..cf3653f90 100644 --- a/log_manager/log_manager.cc +++ b/log_manager/log_manager.cc @@ -1349,47 +1349,6 @@ int skygw_log_flush(logfile_id_t id) return err; } -/** - * Replace current logfile with new file with increased sequence number on - * its name. - */ -int skygw_log_rotate(logfile_id_t id) -{ - int err = -1; - - if (id == LOGFILE_ERROR) - { - if (logmanager_register(false)) - { - CHK_LOGMANAGER(lm); - - logfile_t *lf = logmanager_get_logfile(lm); - CHK_LOGFILE(lf); - - MXS_NOTICE("Log rotation is called for %s.", lf->lf_full_file_name); - - logfile_rotate(lf); - err = 0; - - logmanager_unregister(); - } - else - { - ss_dfprintf(stderr, "Can't register to logmanager, rotating failed.\n"); - } - } - else - { - // We'll pretend everything went ok. - err = 0; - } - - return err; -} - - - - /** * @node Register as a logging client to logmanager. * @@ -2717,7 +2676,28 @@ int mxs_log_flush() */ int mxs_log_rotate() { - return skygw_log_rotate(LOGFILE_ERROR); + int err = -1; + + if (logmanager_register(false)) + { + CHK_LOGMANAGER(lm); + + logfile_t *lf = logmanager_get_logfile(lm); + CHK_LOGFILE(lf); + + MXS_NOTICE("Log rotation is called for %s.", lf->lf_full_file_name); + + logfile_rotate(lf); + err = 0; + + logmanager_unregister(); + } + else + { + ss_dfprintf(stderr, "Can't register to logmanager, rotating failed.\n"); + } + + return err; } static bool convert_priority_to_file(int priority, logfile_id_t* idp, const char** textp) diff --git a/log_manager/log_manager.h b/log_manager/log_manager.h index 76eb14b35..be52d7675 100644 --- a/log_manager/log_manager.h +++ b/log_manager/log_manager.h @@ -159,7 +159,6 @@ void skygw_logmanager_exit(void); void skygw_log_done(void); int skygw_log_flush(logfile_id_t id); void skygw_log_sync_all(void); -int skygw_log_rotate(logfile_id_t id); int skygw_log_enable(logfile_id_t id); int skygw_log_disable(logfile_id_t id); void skygw_log_sync_all(void); diff --git a/server/core/gateway.c b/server/core/gateway.c index 29e6cfaa8..051387071 100644 --- a/server/core/gateway.c +++ b/server/core/gateway.c @@ -307,10 +307,7 @@ static void sigusr1_handler (int i) LOGIF(LM, (skygw_log_write( LOGFILE_MESSAGE, "Log file flush following reception of SIGUSR1\n"))); - skygw_log_rotate(LOGFILE_ERROR); - skygw_log_rotate(LOGFILE_MESSAGE); - skygw_log_rotate(LOGFILE_TRACE); - skygw_log_rotate(LOGFILE_DEBUG); + mxs_log_rotate(); } static void sigterm_handler (int i) { diff --git a/server/modules/routing/debugcmd.c b/server/modules/routing/debugcmd.c index 414692e76..137f9e7bd 100644 --- a/server/modules/routing/debugcmd.c +++ b/server/modules/routing/debugcmd.c @@ -613,29 +613,48 @@ struct subcommand removeoptions[] = { static void flushlog(DCB *pdcb, char *logname) { - if (logname == NULL) + bool unrecognized = false; + bool deprecated = false; + + if (!strcasecmp(logname, "error")) { - } - else if (!strcasecmp(logname, "error")) - { - skygw_log_rotate(LOGFILE_ERROR); + deprecated = true; } else if (!strcasecmp(logname, "message")) { - skygw_log_rotate(LOGFILE_MESSAGE); + deprecated = true; } else if (!strcasecmp(logname, "trace")) { - skygw_log_rotate(LOGFILE_TRACE); + deprecated = true; } else if (!strcasecmp(logname, "debug")) { - skygw_log_rotate(LOGFILE_DEBUG); + deprecated = true; + } + else if (!strcasecmp(logname, "maxscale")) + { + ; // nop } else { - dcb_printf(pdcb, "Unexpected logfile name, expected " - "error, message, trace or debug.\n"); + unrecognized = true; + } + + if (unrecognized) + { + dcb_printf(pdcb, "Unexpected logfile name '%s', expected: 'maxscale'.\n", logname); + } + else + { + mxs_log_rotate(); + + if (deprecated) + { + dcb_printf(pdcb, + "'%s' is deprecated, currently there is only one log 'maxscale', " + "which was rotated.\n", logname); + } } } @@ -647,10 +666,7 @@ flushlog(DCB *pdcb, char *logname) static void flushlogs(DCB *pdcb) { - skygw_log_rotate(LOGFILE_ERROR); - skygw_log_rotate(LOGFILE_MESSAGE); - skygw_log_rotate(LOGFILE_TRACE); - skygw_log_rotate(LOGFILE_DEBUG); + mxs_log_rotate(); } @@ -670,8 +686,8 @@ struct subcommand flushoptions[] = { "logs", 0, flushlogs, - "Flush the content of all log files, close that logs, rename them and open a new log files", - "Flush the content of all log files, close that logs, rename them and open a new log files", + "Flush the content of all log files, close those logs, rename them and open a new log files", + "Flush the content of all log files, close those logs, rename them and open a new log files", {0, 0, 0} }, { diff --git a/server/modules/routing/maxinfo/maxinfo_exec.c b/server/modules/routing/maxinfo/maxinfo_exec.c index 3c2b0849d..b3c59c1dd 100644 --- a/server/modules/routing/maxinfo/maxinfo_exec.c +++ b/server/modules/routing/maxinfo/maxinfo_exec.c @@ -303,10 +303,7 @@ char errmsg[120]; */ void exec_flush_logs(DCB *dcb, MAXINFO_TREE *tree) { - skygw_log_rotate(LE); - skygw_log_rotate(LM); - skygw_log_rotate(LT); - skygw_log_rotate(LD); + mxs_log_rotate(); maxinfo_send_ok(dcb); } @@ -1252,4 +1249,4 @@ void maxinfo_send_ok(DCB *dcb) memcpy(buffer->start, ok_packet, sizeof(ok_packet)); dcb->func.write(dcb, buffer); } -} \ No newline at end of file +}