From 7d8becc8e5bf9710398864b3e11eaf87f727f6cb Mon Sep 17 00:00:00 2001 From: Andreas Huggel Date: Sat, 10 Dec 2011 08:51:07 +0000 Subject: [PATCH] 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. --- src/error.cpp | 4 ++-- src/error.hpp | 2 +- src/exiv2.1 | 5 +++++ src/exiv2.cpp | 21 +++++++++++++++++++++ src/exiv2app.hpp | 3 ++- src/tiffimage.cpp | 8 ++++---- test/data/exiv2-test.out | 1 + 7 files changed, 36 insertions(+), 8 deletions(-) diff --git a/src/error.cpp b/src/error.cpp index d6db58eb..5c5fc2d3 100644 --- a/src/error.cpp +++ b/src/error.cpp @@ -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(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); diff --git a/src/error.hpp b/src/error.hpp index 2f02b132..084bca20 100644 --- a/src/error.hpp +++ b/src/error.hpp @@ -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; } diff --git a/src/exiv2.1 b/src/exiv2.1 index 02071196..e11c2891 100644 --- a/src/exiv2.1 +++ b/src/exiv2.1 @@ -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 diff --git a/src/exiv2.cpp b/src/exiv2.cpp index f1208252..f3abf1ab 100644 --- a/src/exiv2.cpp +++ b/src/exiv2.cpp @@ -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; diff --git a/src/exiv2app.hpp b/src/exiv2app.hpp index 0c30610e..8cbbedff 100644 --- a/src/exiv2app.hpp +++ b/src/exiv2app.hpp @@ -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); diff --git a/src/tiffimage.cpp b/src/tiffimage.cpp index 7e94aea0..d588a1f8 100644 --- a/src/tiffimage.cpp +++ b/src/tiffimage.cpp @@ -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; diff --git a/test/data/exiv2-test.out b/test/data/exiv2-test.out index 771e421a..8a64ce59 100644 --- a/test/data/exiv2-test.out +++ b/test/data/exiv2-test.out @@ -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).