Print diagnostic messages to stderr

They contain errors and debugging information so stderr fits better. This
also ensures they don't conflict with the output, e.g. when extracting to
stdout.
This commit is contained in:
Martchus 2022-05-21 13:17:16 +02:00
parent b26b972e25
commit 794afdb01e
2 changed files with 19 additions and 20 deletions

View File

@ -173,7 +173,7 @@ void printDiagMessages(const Diagnostics &diag, const char *head, bool beVerbose
printDiagMsg:
if (head) {
cout << " - " << head << endl;
cerr << " - " << head << endl;
}
for (const auto &message : diag) {
switch (message.level()) {
@ -181,37 +181,37 @@ printDiagMsg:
if (!beVerbose) {
continue;
}
cout << " Debug ";
cerr << " Debug ";
break;
case DiagLevel::Information:
if (!beVerbose) {
continue;
}
cout << " Information ";
cerr << " Information ";
break;
case DiagLevel::Warning:
setStyle(cout, Color::Yellow, ColorContext::Foreground, TextAttribute::Bold);
setStyle(cout, TextAttribute::Reset);
setStyle(cout, TextAttribute::Bold);
cout << " Warning ";
setStyle(cout, TextAttribute::Reset);
setStyle(cerr, Color::Yellow, ColorContext::Foreground, TextAttribute::Bold);
setStyle(cerr, TextAttribute::Reset);
setStyle(cerr, TextAttribute::Bold);
cerr << " Warning ";
setStyle(cerr, TextAttribute::Reset);
break;
case DiagLevel::Critical:
case DiagLevel::Fatal:
setStyle(cout, Color::Red, ColorContext::Foreground, TextAttribute::Bold);
setStyle(cout, TextAttribute::Reset);
setStyle(cout, TextAttribute::Bold);
cout << " Error ";
setStyle(cout, TextAttribute::Reset);
setStyle(cerr, Color::Red, ColorContext::Foreground, TextAttribute::Bold);
setStyle(cerr, TextAttribute::Reset);
setStyle(cerr, TextAttribute::Bold);
cerr << " Error ";
setStyle(cerr, TextAttribute::Reset);
if (message.level() == DiagLevel::Fatal && exitCode == EXIT_SUCCESS) {
exitCode = EXIT_PARSING_FAILURE;
}
break;
default:;
}
cout << message.creationTime().toString(DateTimeOutputFormat::TimeOnly) << " ";
cout << message.context() << ": ";
cout << message.message() << '\n';
cerr << message.creationTime().toString(DateTimeOutputFormat::TimeOnly) << " ";
cerr << message.context() << ": ";
cerr << message.message() << '\n';
}
}

View File

@ -332,11 +332,10 @@ void CliTests::testSpecifyingNativeFieldIds()
const char *const args1[] = { "tageditor", "set", "mkv:FOO=bar", "mp4:©foo=bar", "mp4:invalid", "vorbis:BAR=foo", "-f", mkvFile.data(),
mp4File.data(), vorbisFile.data(), opusFile.data(), nullptr };
TESTUTILS_ASSERT_EXEC(args1);
CPPUNIT_ASSERT(stderr.empty());
// FIXME: provide a way to specify raw data type
CPPUNIT_ASSERT(testContainsSubstrings(
stdout, { "making MP4 tag field ©foo: It was not possible to find an appropriate raw data type id. UTF-8 will be assumed." }));
CPPUNIT_ASSERT(testContainsSubstrings(stdout, { "Unable to parse denoted field ID \"invalid\": MP4 ID must be exactly 4 chars" }));
stderr, { "making MP4 tag field ©foo: It was not possible to find an appropriate raw data type id. UTF-8 will be assumed." }));
CPPUNIT_ASSERT(testContainsSubstrings(stderr, { "Unable to parse denoted field ID \"invalid\": MP4 ID must be exactly 4 chars" }));
const char *const args2[]
= { "tageditor", "get", "mkv:FOO", "mp4:©foo", "vorbis:BAR", "generic:year", "generic:releasedate", "-f", mkvFile.data(), nullptr };
@ -532,7 +531,7 @@ void CliTests::testEncodingOption()
mp3File1.data(), nullptr };
TESTUTILS_ASSERT_EXEC(args1);
CPPUNIT_ASSERT(
stdout.find(
stderr.find(
"setting tags: Can't use specified encoding \"utf8\" in ID3v2 tag (version 2.3.0) because the tag format/version doesn't support it.")
!= string::npos);