Cleanup early error logging

If the log file could not be opened, it was reported over and
over and over again to stderr.
This commit is contained in:
Johan Wikman
2016-09-06 10:50:13 +03:00
parent ca6c619d60
commit 0aec0c483c
2 changed files with 16 additions and 22 deletions

View File

@ -693,30 +693,27 @@ static void print_log_n_stderr(
const char* fprstr, /*< string to be printed to stderr */
int eno) /*< errno, if it is set, zero, otherwise */
{
char* log_err = "Error :";
char* fpr_err = "*\n* Error :";
char* fpr_end = "\n*\n";
if (do_log)
{
mxs_log_init(NULL, get_logdir(), MXS_LOG_TARGET_FS);
char errbuf[STRERROR_BUFLEN];
MXS_ERROR("%s %s %s %s",
log_err,
logstr,
eno == 0 ? " " : "Error :",
eno == 0 ? " " : strerror_r(eno, errbuf, sizeof(errbuf)));
if (mxs_log_init(NULL, get_logdir(), MXS_LOG_TARGET_FS))
{
char errbuf[STRERROR_BUFLEN];
MXS_ERROR("%s%s%s%s",
logstr,
eno == 0 ? "" : " (",
eno == 0 ? "" : strerror_r(eno, errbuf, sizeof(errbuf)),
eno == 0 ? "" : ")");
}
}
if (do_stderr)
{
char errbuf[STRERROR_BUFLEN];
fprintf(stderr,
"%s %s %s %s %s",
fpr_err,
"* Error: %s%s%s%s\n",
fprstr,
eno == 0 ? " " : "Error :",
eno == 0 ? " " : strerror_r(eno, errbuf, sizeof(errbuf)),
fpr_end);
eno == 0 ? "" : " (",
eno == 0 ? "" : strerror_r(eno, errbuf, sizeof(errbuf)),
eno == 0 ? "" : ")");
}
}