LOGIF and skygw_write_log removed from server/core/*.c

LOGIF and skygw_write_log removed from server/core/*.c and
replaced with calls to MXS_(ERROR|WARNING|NOTICE|INFO|DEBUG).
This is a mechanism change, no updating of the actual message
has been performed.

Currently this causes a very small performance hit, since the
check whether the priority is enabled or not is performed in
the function that is called and not before the function is called.
Once all LOGIFs and skygw_write_logs have been replaced, the
behaviour will be altered back to what it was.
This commit is contained in:
Johan Wikman
2015-11-15 19:37:15 +02:00
parent 1f15843d61
commit 44df53d846
19 changed files with 1367 additions and 1992 deletions

View File

@ -292,9 +292,7 @@ static void maxscale_ssl_id(CRYPTO_THREADID* id)
*/
static void sighup_handler (int i)
{
LOGIF(LM, (skygw_log_write(
LOGFILE_MESSAGE,
"Refreshing configuration following SIGHUP\n")));
MXS_NOTICE("Refreshing configuration following SIGHUP\n");
config_reload();
}
@ -304,18 +302,14 @@ static void sighup_handler (int i)
*/
static void sigusr1_handler (int i)
{
LOGIF(LM, (skygw_log_write(
LOGFILE_MESSAGE,
"Log file flush following reception of SIGUSR1\n")));
MXS_NOTICE("Log file flush following reception of SIGUSR1\n");
mxs_log_rotate();
}
static void sigterm_handler (int i) {
extern void shutdown_server();
skygw_log_write_flush(
LOGFILE_ERROR,
"MaxScale received signal SIGTERM. Exiting.");
MXS_ERROR("MaxScale received signal SIGTERM. Exiting.");
mxs_log_flush_sync();
shutdown_server();
}
@ -325,9 +319,7 @@ sigint_handler (int i)
{
extern void shutdown_server();
skygw_log_write_flush(
LOGFILE_ERROR,
"MaxScale received signal SIGINT. Shutting down.");
MXS_ERROR("MaxScale received signal SIGINT. Shutting down.");
mxs_log_flush_sync();
shutdown_server();
fprintf(stderr, "\n\nShutting down MaxScale\n\n");
@ -342,28 +334,33 @@ sigchld_handler (int i)
if ((child = wait(&exit_status)) == -1)
{
char errbuf[STRERROR_BUFLEN];
skygw_log_write_flush(LE, "Error: failed to wait child process: %d %s",
errno, strerror_r(errno, errbuf, sizeof(errbuf)));
MXS_ERROR("Failed to wait child process: %d %s",
errno, strerror_r(errno, errbuf, sizeof(errbuf)));
}
else
{
if (WIFEXITED(exit_status))
{
skygw_log_write_flush(WEXITSTATUS(exit_status) != 0 ? LE : LT,
"Child process %d exited with status %d",
child, WEXITSTATUS(exit_status));
if (WEXITSTATUS(exit_status) != 0)
{
MXS_ERROR("Child process %d exited with status %d",
child, WEXITSTATUS(exit_status));
}
else
{
MXS_INFO("Child process %d exited with status %d",
child, WEXITSTATUS(exit_status));
}
}
else if (WIFSIGNALED(exit_status))
{
skygw_log_write_flush((LE|LT),
"Child process %d was stopped by signal %d.",
child, WTERMSIG(exit_status));
MXS_ERROR("Child process %d was stopped by signal %d.",
child, WTERMSIG(exit_status));
}
else
{
skygw_log_write_flush((LE|LT),
"Child process %d did not exit normally. Exit status: %d",
child, exit_status);
MXS_ERROR("Child process %d did not exit normally. Exit status: %d",
child, exit_status);
}
}
}
@ -383,13 +380,11 @@ sigfatal_handler(int i)
GATEWAY_CONF* cnf = config_get_global_options();
fprintf(stderr, "\n\nMaxScale "MAXSCALE_VERSION" received fatal signal %d\n", i);
skygw_log_write_flush(
LOGFILE_ERROR,
"Fatal: MaxScale "MAXSCALE_VERSION" received fatal signal %d. Attempting backtrace.", i);
MXS_ERROR("Fatal: MaxScale "MAXSCALE_VERSION" received fatal signal %d. Attempting backtrace.", i);
skygw_log_write_flush(LE, "Commit ID: %s System name: %s "
"Release string: %s Embedded library version: %s",
maxscale_commit, cnf->sysname, cnf->release_string, cnf->version_string);
MXS_ERROR("Commit ID: %s System name: %s "
"Release string: %s Embedded library version: %s",
maxscale_commit, cnf->sysname, cnf->release_string, cnf->version_string);
{
void *addrs[128];
@ -398,9 +393,7 @@ sigfatal_handler(int i)
if (symbols) {
for (n = 0; n < count; n++) {
skygw_log_write_flush(
LOGFILE_ERROR,
" %s\n", symbols[n]);
MXS_ERROR(" %s\n", symbols[n]);
}
free(symbols);
} else {
@ -446,12 +439,10 @@ static int signal_set(int sig, void (*handler)(int)) {
int eno = errno;
errno = 0;
char errbuf[STRERROR_BUFLEN];
skygw_log_write_flush(
LOGFILE_ERROR,
"Error : Failed call sigaction() in %s due to %d, %s.",
program_invocation_short_name,
eno,
strerror_r(eno, errbuf, sizeof(errbuf)));
MXS_ERROR("Failed call sigaction() in %s due to %d, %s.",
program_invocation_short_name,
eno,
strerror_r(eno, errbuf, sizeof(errbuf)));
rc = 1;
}
return rc;
@ -475,13 +466,11 @@ int ntfw_cb(
int eno = errno;
errno = 0;
char errbuf[STRERROR_BUFLEN];
skygw_log_write(
LOGFILE_ERROR,
"Error : Failed to remove the data directory %s of "
"MaxScale due to %d, %s.",
datadir,
eno,
strerror_r(eno, errbuf, sizeof(errbuf)));
MXS_ERROR("Failed to remove the data directory %s of "
"MaxScale due to %d, %s.",
datadir,
eno,
strerror_r(eno, errbuf, sizeof(errbuf)));
}
return rc;
}
@ -776,13 +765,11 @@ static void print_log_n_stderr(
if (do_log) {
char errbuf[STRERROR_BUFLEN];
skygw_log_write_flush(
LOGFILE_ERROR,
"%s %s %s %s",
log_err,
logstr,
eno == 0 ? " " : "Error :",
eno == 0 ? " " : strerror_r(eno, errbuf, sizeof(errbuf)));
MXS_ERROR("%s %s %s %s",
log_err,
logstr,
eno == 0 ? " " : "Error :",
eno == 0 ? " " : strerror_r(eno, errbuf, sizeof(errbuf)));
}
if (do_stderr) {
char errbuf[STRERROR_BUFLEN];
@ -815,13 +802,11 @@ static bool file_is_readable(
absolute_pathname,
strerror_r(eno, errbuf, sizeof(errbuf)));
}
skygw_log_write_flush(
LOGFILE_ERROR,
"Warning : Failed to read the configuration file %s due "
"to %d, %s.",
absolute_pathname,
eno,
strerror_r(eno, errbuf, sizeof(errbuf)));
MXS_WARNING("Failed to read the configuration file %s due "
"to %d, %s.",
absolute_pathname,
eno,
strerror_r(eno, errbuf, sizeof(errbuf)));
mxs_log_flush_sync();
succp = false;
}
@ -848,13 +833,11 @@ static bool file_is_writable(
eno,
strerror_r(eno, errbuf, sizeof(errbuf)));
}
skygw_log_write_flush(
LOGFILE_ERROR,
"Error : unable to open file %s for write due "
"to %d, %s.",
absolute_pathname,
eno,
strerror_r(eno, errbuf, sizeof(errbuf)));
MXS_ERROR("Unable to open file %s for write due "
"to %d, %s.",
absolute_pathname,
eno,
strerror_r(eno, errbuf, sizeof(errbuf)));
succp = false;
}
return succp;
@ -909,14 +892,11 @@ static char* get_expanded_pathname(
relative_path,
strerror_r(eno, errbuf, sizeof(errbuf)));
skygw_log_write_flush(
LOGFILE_ERROR,
"Warning : Failed to read the "
"directory %s, due "
"to %d, %s.",
relative_path,
eno,
strerror_r(eno, errbuf, sizeof(errbuf)));
MXS_WARNING("Failed to read the directory %s, due "
"to %d, %s.",
relative_path,
eno,
strerror_r(eno, errbuf, sizeof(errbuf)));
free(expanded_path);
*output_path = NULL;
goto return_cnf_file_buf;
@ -939,10 +919,8 @@ static char* get_expanded_pathname(
ss_dassert(cnf_file_buf != NULL);
char errbuf[STRERROR_BUFLEN];
skygw_log_write_flush(
LOGFILE_ERROR,
"Error : Memory allocation failed due to %s.",
strerror_r(errno, errbuf, sizeof(errbuf)));
MXS_ERROR("Memory allocation failed due to %s.",
strerror_r(errno, errbuf, sizeof(errbuf)));
free(expanded_path);
expanded_path = NULL;
@ -1672,7 +1650,7 @@ int main(int argc, char **argv)
snprintf(errorbuffer, sizeof(errorbuffer),
"Error: Failed to pre-parse configuration file. Memory allocation failed.");
skygw_log_write(LE, errorbuffer);
MXS_ERROR("%s", errorbuffer);
if (!daemon_mode)
{
strncat(errorbuffer, "\n", STRING_BUFFER_SIZE);
@ -1775,29 +1753,11 @@ int main(int argc, char **argv)
get_cachedir());
}
LOGIF(LM,
(skygw_log_write_flush(
LOGFILE_MESSAGE,
"Configuration file: %s",
cnf_file_path)));
LOGIF(LM,
(skygw_log_write_flush(
LOGFILE_MESSAGE,
"Log directory: %s/",
get_logdir())));
LOGIF(LM,
(skygw_log_write_flush(
LOGFILE_MESSAGE,
"Data directory: %s",
get_datadir())));
LOGIF(LM,
(skygw_log_write_flush(LOGFILE_MESSAGE,
"Module directory: %s",
get_libdir())));
LOGIF(LM,
(skygw_log_write_flush(LOGFILE_MESSAGE,
"Service cache: %s",
get_cachedir())));
MXS_NOTICE("Configuration file: %s", cnf_file_path);
MXS_NOTICE("Log directory: %s", get_logdir());
MXS_NOTICE("Data directory: %s", get_datadir());
MXS_NOTICE("Module directory: %s", get_libdir());
MXS_NOTICE("Service cache: %s", get_cachedir());
/*< Update the server options */
for (i = 0; server_options[i]; i++)
@ -1854,15 +1814,13 @@ int main(int argc, char **argv)
}
}
}
skygw_log_write_flush(
LOGFILE_ERROR,
"Error : mysql_library_init failed. It is a "
"mandatory component, required by router services and "
"the MaxScale core. Error %d, %s, %s : %d. Exiting.",
mysql_errno(NULL),
mysql_error(NULL),
__FILE__,
__LINE__);
MXS_ERROR("mysql_library_init failed. It is a "
"mandatory component, required by router services and "
"the MaxScale core. Error %d, %s, %s : %d. Exiting.",
mysql_errno(NULL),
mysql_error(NULL),
__FILE__,
__LINE__);
rc = MAXSCALE_NOLIBRARY;
goto return_main;
}
@ -1873,22 +1831,14 @@ int main(int argc, char **argv)
char* fprerr = "Failed to load MaxScale configuration "
"file. Exiting. See the error log for details.";
print_log_n_stderr(false, !daemon_mode, fprerr, fprerr, 0);
skygw_log_write_flush(
LOGFILE_ERROR,
"Error : Failed to load MaxScale configuration file %s. "
"Exiting.",
cnf_file_path);
MXS_ERROR("Failed to load MaxScale configuration file %s. "
"Exiting.",
cnf_file_path);
rc = MAXSCALE_BADCONFIG;
goto return_main;
}
LOGIF(LM, (skygw_log_write(
LOGFILE_MESSAGE,
"MariaDB Corporation MaxScale %s (C) MariaDB Corporation Ab 2013-2015",
MAXSCALE_VERSION)));
LOGIF(LM, (skygw_log_write(
LOGFILE_MESSAGE,
"MaxScale is running in process %i",
getpid())));
MXS_NOTICE("MariaDB Corporation MaxScale %s (C) MariaDB Corporation Ab 2013-2015", MAXSCALE_VERSION);
MXS_NOTICE("MaxScale is running in process %i", getpid());
/** Check if a MaxScale process is already running */
if (pid_file_exists())
@ -1952,9 +1902,7 @@ int main(int argc, char **argv)
{
threads[thread_id] = thread_start(poll_waitevents, (void *)(thread_id + 1));
}
LOGIF(LM, (skygw_log_write(LOGFILE_MESSAGE,
"MaxScale started with %d server threads.",
config_threadcount())));
MXS_NOTICE("MaxScale started with %d server threads.", config_threadcount());
/**
* Successful start, notify the parent process that it can exit.
*/
@ -1983,16 +1931,12 @@ int main(int argc, char **argv)
/*< Stop all the monitors */
monitorStopAll();
LOGIF(LM, (skygw_log_write(
LOGFILE_MESSAGE,
"MaxScale is shutting down.")));
MXS_NOTICE("MaxScale is shutting down.");
/** Release mysql thread context*/
mysql_thread_end();
datadir_cleanup();
LOGIF(LM, (skygw_log_write(
LOGFILE_MESSAGE,
"MaxScale shutdown completed.")));
MXS_NOTICE("MaxScale shutdown completed.");
unload_all_modules();
/* Remove Pidfile */
@ -2052,14 +1996,12 @@ static void log_flush_cb(
ts1.tv_sec = timeout_ms/1000;
ts1.tv_nsec = (timeout_ms%1000) * 1000000;
LOGIF(LM, (skygw_log_write(LOGFILE_MESSAGE,
"Started MaxScale log flusher.")));
MXS_NOTICE("Started MaxScale log flusher.");
while (!do_exit) {
mxs_log_flush();
nanosleep(&ts1, NULL);
}
LOGIF(LM, (skygw_log_write(LOGFILE_MESSAGE,
"Finished MaxScale log flusher.")));
MXS_NOTICE("Finished MaxScale log flusher.");
}
static void unlock_pidfile()