Skip to content

Commit 3ce0f79

Browse files
committed
Improvement of WARN_LOGFILE possibilities
Improvement of the error / warning handling output in respect to the output file used: - warning when the specified cannot be opened - possibility to write warnings to stdout instead of the default stderr (useful for redirecting output on, especially, windows so output will not be "garbled").
1 parent cc31762 commit 3ce0f79

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

Diff for: src/config.xml

+4-1
Original file line numberDiff line numberDiff line change
@@ -1366,7 +1366,10 @@ FILE_VERSION_FILTER = "cleartool desc -fmt \%Vn"
13661366
<![CDATA[
13671367
The \c WARN_LOGFILE tag can be used to specify a file to which warning
13681368
and error messages should be written. If left blank the output is written
1369-
to standard error (`stderr`).
1369+
to standard error (`stderr`). In case the file specified cannot be opened for
1370+
writing the warning and error messages are written to standard error. When as
1371+
file `-` is specified the warning and error messages are written to standard output
1372+
(`stdout`).
13701373
]]>
13711374
</docs>
13721375
</option>

Diff for: src/message.cpp

+13-3
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,22 @@ static std::mutex g_mutex;
4242
void initWarningFormat()
4343
{
4444
outputFormat = Config_getString(WARN_FORMAT);
45+
QCString logFile = Config_getString(WARN_LOGFILE);
4546

46-
if (!Config_getString(WARN_LOGFILE).isEmpty())
47+
if (!logFile.isEmpty())
4748
{
48-
warnFile = Portable::fopen(Config_getString(WARN_LOGFILE),"w");
49+
if (logFile == "-")
50+
{
51+
warnFile = stdout;
52+
}
53+
else if (!(warnFile = Portable::fopen(logFile,"w")))
54+
{
55+
// point it to something valid, because warn() relies on it
56+
warnFile = stderr;
57+
err("Cannot open '%s' for writing, redirecting 'WARN_LOGFILE' output to 'stderr'\n",logFile.data());
58+
}
4959
}
50-
if (!warnFile) // point it to something valid, because warn() relies on it
60+
else
5161
{
5262
warnFile = stderr;
5363
}

0 commit comments

Comments
 (0)