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 */ const char* fprstr, /*< string to be printed to stderr */
int eno) /*< errno, if it is set, zero, otherwise */ 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) if (do_log)
{ {
mxs_log_init(NULL, get_logdir(), MXS_LOG_TARGET_FS); if (mxs_log_init(NULL, get_logdir(), MXS_LOG_TARGET_FS))
char errbuf[STRERROR_BUFLEN]; {
MXS_ERROR("%s %s %s %s", char errbuf[STRERROR_BUFLEN];
log_err, MXS_ERROR("%s%s%s%s",
logstr, logstr,
eno == 0 ? " " : "Error :", eno == 0 ? "" : " (",
eno == 0 ? " " : strerror_r(eno, errbuf, sizeof(errbuf))); eno == 0 ? "" : strerror_r(eno, errbuf, sizeof(errbuf)),
eno == 0 ? "" : ")");
}
} }
if (do_stderr) if (do_stderr)
{ {
char errbuf[STRERROR_BUFLEN]; char errbuf[STRERROR_BUFLEN];
fprintf(stderr, fprintf(stderr,
"%s %s %s %s %s", "* Error: %s%s%s%s\n",
fpr_err,
fprstr, fprstr,
eno == 0 ? " " : "Error :", eno == 0 ? "" : " (",
eno == 0 ? " " : strerror_r(eno, errbuf, sizeof(errbuf)), eno == 0 ? "" : strerror_r(eno, errbuf, sizeof(errbuf)),
fpr_end); eno == 0 ? "" : ")");
} }
} }

View File

@ -443,7 +443,7 @@ return_succ:
{ {
/** This releases memory of all created objects */ /** This releases memory of all created objects */
logmanager_done_nomutex(); logmanager_done_nomutex();
fprintf(stderr, "*\n* Error : Initializing log manager failed.\n*\n"); fprintf(stderr, "* Error: Initializing the log manager failed.\n");
} }
return succ; return succ;
} }
@ -1566,7 +1566,7 @@ static bool logfile_open_file(filewriter_t* fw, logfile_t* lf)
if (fw->fwr_file == NULL) if (fw->fwr_file == NULL)
{ {
fprintf(stderr, "Error : opening logfile %s failed.\n", lf->lf_full_file_name); // Error logged by skygw_file_init to stderr.
rv = false; rv = false;
} }
@ -2035,10 +2035,7 @@ static bool filewriter_init(logmanager_t* logmanager, filewriter_t* fw)
} }
else else
{ {
fprintf(stderr, // Error logged already to stderr.
"Error : opening log file %s failed. Exiting "
"MaxScale\n",
lf->lf_full_file_name);
filewriter_done(fw); filewriter_done(fw);
} }