Added -Q option to the utility, set the default log level for LogMsg to "warn", converted debug message about write strategy to an EXV_INFO log message.

This commit is contained in:
Andreas Huggel 2011-12-10 08:51:07 +00:00
parent df6e17fdae
commit 7d8becc8e5
7 changed files with 36 additions and 8 deletions

View File

@ -114,14 +114,14 @@ namespace {
// class member definitions
namespace Exiv2 {
LogMsg::Level LogMsg::level_ = LogMsg::info; // Default output level
LogMsg::Level LogMsg::level_ = LogMsg::warn; // Default output level
LogMsg::Handler LogMsg::handler_ = LogMsg::defaultHandler;
void LogMsg::defaultHandler(int level, const char* s)
{
switch (static_cast<LogMsg::Level>(level)) {
case LogMsg::debug: std::cerr << "Debug: "; break;
case LogMsg::info: break;
case LogMsg::info: std::cerr << "Info: "; break;
case LogMsg::warn: std::cerr << "Warning: "; break;
case LogMsg::error: std::cerr << "Error: "; break;
case LogMsg::mute: assert(false);

View File

@ -110,7 +110,7 @@ namespace Exiv2 {
/*!
@brief Set the log level. Only log messages with a level greater or
equal \em level are sent to the log message handler. Default
log level is \c info. To suppress all log messages, set the log
log level is \c warn. To suppress all log messages, set the log
level to \c mute (or set the log message handler to 0).
*/
static void setLevel(Level level) { level_ = level; }

View File

@ -134,6 +134,11 @@ Silence warnings and error messages from the Exiv2 library during the
program run (quiet). Note that options \fB\-v\fP and \fB\-q\fP can be
used at the same time.
.TP
.B \-Q \fIlvl\fP
Set the log-level to 'd'(ebug), 'i'(nfo), 'w'(arning), 'e'(rror)
or 'm'(ute). The default log-level is 'w'. \fB\-Qm\fP is equivalent
to \fB\-q\fP. All log messages are written to standard error.
.TP
.B \-b
Show large binary values (default is to suppress them).
.TP

View File

@ -260,6 +260,7 @@ void Params::help(std::ostream& os) const
<< _(" -V Show the program version and exit.\n")
<< _(" -v Be verbose during the program run.\n")
<< _(" -q Silence warnings and error messages during the program run (quiet).\n")
<< _(" -Q lvl Set log-level to d(ebug), i(nfo), w(arning), e(rror) or m(ute).\n")
<< _(" -b Show large binary values.\n")
<< _(" -u Show unknown tags.\n")
<< _(" -g key Only output info for this key (grep).\n")
@ -341,6 +342,7 @@ int Params::option(int opt, const std::string& optarg, int optopt)
case 'V': version_ = true; break;
case 'v': verbose_ = true; break;
case 'q': Exiv2::LogMsg::setLevel(Exiv2::LogMsg::mute); break;
case 'Q': rc = setLogLevel(optarg); break;
case 'k': preserve_ = true; break;
case 'b': binary_ = false; break;
case 'u': unknown_ = false; break;
@ -385,6 +387,25 @@ int Params::option(int opt, const std::string& optarg, int optopt)
return rc;
} // Params::option
int Params::setLogLevel(const std::string& optarg)
{
int rc = 0;
const char logLevel = tolower(optarg[0]);
switch (logLevel) {
case 'd': Exiv2::LogMsg::setLevel(Exiv2::LogMsg::debug); break;
case 'i': Exiv2::LogMsg::setLevel(Exiv2::LogMsg::info); break;
case 'w': Exiv2::LogMsg::setLevel(Exiv2::LogMsg::warn); break;
case 'e': Exiv2::LogMsg::setLevel(Exiv2::LogMsg::error); break;
case 'm': Exiv2::LogMsg::setLevel(Exiv2::LogMsg::mute); break;
default:
std::cerr << progname() << ": " << _("Option") << " -Q: "
<< _("Invalid argument") << " \"" << optarg << "\"\n";
rc = 1;
break;
}
return rc;
} // Params::setLogLevel
int Params::evalRename(int opt, const std::string& optarg)
{
int rc = 0;

View File

@ -220,7 +220,7 @@ private:
@brief Default constructor. Note that optstring_ is initialized here.
The c'tor is private to force instantiation through instance().
*/
Params() : optstring_(":hVvqfbuktTFa:Y:O:D:r:p:P:d:e:i:c:m:M:l:S:g:n:"),
Params() : optstring_(":hVvqfbuktTFa:Y:O:D:r:p:P:d:e:i:c:m:M:l:S:g:n:Q:"),
help_(false),
version_(false),
verbose_(false),
@ -252,6 +252,7 @@ private:
//! @name Helpers
//@{
int setLogLevel(const std::string& optarg);
int evalRename(int opt, const std::string& optarg);
int evalAdjust(const std::string& optarg);
int evalYodAdjust(const Yod& yod, const std::string& optarg);

View File

@ -1874,13 +1874,13 @@ namespace Exiv2 {
uint32_t(-1),
imageIdx);
io.transfer(*tempIo); // may throw
#ifdef DEBUG
std::cerr << "Intrusive writing\n";
#ifndef SUPPRESS_WARNINGS
EXV_INFO << "Write strategy: Intrusive\n";
#endif
}
#ifdef DEBUG
#ifndef SUPPRESS_WARNINGS
else {
std::cerr << "Non-intrusive writing\n";
EXV_INFO << "Write strategy: Non-intrusive\n";
}
#endif
return writeMethod;

View File

@ -49,6 +49,7 @@ Options:
-V Show the program version and exit.
-v Be verbose during the program run.
-q Silence warnings and error messages during the program run (quiet).
-Q lvl Set log-level to d(ebug), i(nfo), w(arning), e(rror) or m(ute).
-b Show large binary values.
-u Show unknown tags.
-g key Only output info for this key (grep).