#476, #614: Introduced class LogMsg for enhanced logging, migrated all existing warnings and error messages (not the exceptions) to use the new logic. Every log message now has a type (debug, info, warning, error). Applications can set a logging level to determine which messages are processed and supply a custom log message handler at runtime. (Based on a contribution by Simson Garfinkel.)

v0.27.3
Andreas Huggel 15 years ago
parent 1fdf4a3ab5
commit dc264bc00d

@ -571,7 +571,7 @@ namespace Exiv2 {
if (::lstat(pf, &buf1) == -1) { if (::lstat(pf, &buf1) == -1) {
statOk = false; statOk = false;
#ifndef SUPPRESS_WARNINGS #ifndef SUPPRESS_WARNINGS
std::cerr << "Warning: " << Error(2, pf, strError(), "::lstat") << "\n"; EXV_WARNING << Error(2, pf, strError(), "::lstat") << "\n";
#endif #endif
} }
origStMode = buf1.st_mode; origStMode = buf1.st_mode;
@ -588,7 +588,7 @@ namespace Exiv2 {
if (::stat(pf, &buf1) == -1) { if (::stat(pf, &buf1) == -1) {
statOk = false; statOk = false;
#ifndef SUPPRESS_WARNINGS #ifndef SUPPRESS_WARNINGS
std::cerr << "Warning: " << Error(2, pf, strError(), "::stat") << "\n"; EXV_WARNING << Error(2, pf, strError(), "::stat") << "\n";
#endif #endif
} }
origStMode = buf1.st_mode; origStMode = buf1.st_mode;
@ -616,14 +616,14 @@ namespace Exiv2 {
if (statOk && ::_wstat(wpf, &buf2) == -1) { if (statOk && ::_wstat(wpf, &buf2) == -1) {
statOk = false; statOk = false;
#ifndef SUPPRESS_WARNINGS #ifndef SUPPRESS_WARNINGS
std::cerr << "Warning: " << Error(2, wpf, strError(), "::_wstat") << "\n"; EXV_WARNING << Error(2, wpf, strError(), "::_wstat") << "\n";
#endif #endif
} }
if (statOk && origStMode != buf2.st_mode) { if (statOk && origStMode != buf2.st_mode) {
// Set original file permissions // Set original file permissions
if (::_wchmod(wpf, origStMode) == -1) { if (::_wchmod(wpf, origStMode) == -1) {
#ifndef SUPPRESS_WARNINGS #ifndef SUPPRESS_WARNINGS
std::cerr << "Warning: " << Error(2, wpf, strError(), "::_wchmod") << "\n"; EXV_WARNING << Error(2, wpf, strError(), "::_wchmod") << "\n";
#endif #endif
} }
} }
@ -643,14 +643,14 @@ namespace Exiv2 {
if (statOk && ::stat(pf, &buf2) == -1) { if (statOk && ::stat(pf, &buf2) == -1) {
statOk = false; statOk = false;
#ifndef SUPPRESS_WARNINGS #ifndef SUPPRESS_WARNINGS
std::cerr << "Warning: " << Error(2, pf, strError(), "::stat") << "\n"; EXV_WARNING << Error(2, pf, strError(), "::stat") << "\n";
#endif #endif
} }
if (statOk && origStMode != buf2.st_mode) { if (statOk && origStMode != buf2.st_mode) {
// Set original file permissions // Set original file permissions
if (::chmod(pf, origStMode) == -1) { if (::chmod(pf, origStMode) == -1) {
#ifndef SUPPRESS_WARNINGS #ifndef SUPPRESS_WARNINGS
std::cerr << "Warning: " << Error(2, pf, strError(), "::chmod") << "\n"; EXV_WARNING << Error(2, pf, strError(), "::chmod") << "\n";
#endif #endif
} }
} }

@ -487,7 +487,7 @@ namespace Exiv2 {
std::string value = pos->toString(); std::string value = pos->toString();
if (!pos->value().ok()) { if (!pos->value().ok()) {
#ifndef SUPPRESS_WARNINGS #ifndef SUPPRESS_WARNINGS
std::cerr << "Warning: Failed to convert " << from << " to " << to << "\n"; EXV_WARNING << "Failed to convert " << from << " to " << to << "\n";
#endif #endif
return; return;
} }
@ -504,7 +504,7 @@ namespace Exiv2 {
const CommentValue* cv = dynamic_cast<const CommentValue*>(&pos->value()); const CommentValue* cv = dynamic_cast<const CommentValue*>(&pos->value());
if (cv == 0) { if (cv == 0) {
#ifndef SUPPRESS_WARNINGS #ifndef SUPPRESS_WARNINGS
std::cerr << "Warning: Failed to convert " << from << " to " << to << "\n"; EXV_WARNING << "Failed to convert " << from << " to " << to << "\n";
#endif #endif
return; return;
} }
@ -522,7 +522,7 @@ namespace Exiv2 {
std::string value = pos->toString(i); std::string value = pos->toString(i);
if (!pos->value().ok()) { if (!pos->value().ok()) {
#ifndef SUPPRESS_WARNINGS #ifndef SUPPRESS_WARNINGS
std::cerr << "Warning: Failed to convert " << from << " to " << to << "\n"; EXV_WARNING << "Failed to convert " << from << " to " << to << "\n";
#endif #endif
return; return;
} }
@ -544,13 +544,13 @@ namespace Exiv2 {
std::string value = pos->toString(); std::string value = pos->toString();
if (!pos->value().ok()) { if (!pos->value().ok()) {
#ifndef SUPPRESS_WARNINGS #ifndef SUPPRESS_WARNINGS
std::cerr << "Warning: Failed to convert " << from << " to " << to << "\n"; EXV_WARNING << "Failed to convert " << from << " to " << to << "\n";
#endif #endif
return; return;
} }
if (sscanf(value.c_str(), "%d:%d:%d %d:%d:%d", &year, &month, &day, &hour, &min, &sec) != 6) { if (sscanf(value.c_str(), "%d:%d:%d %d:%d:%d", &year, &month, &day, &hour, &min, &sec) != 6) {
#ifndef SUPPRESS_WARNINGS #ifndef SUPPRESS_WARNINGS
std::cerr << "Warning: Failed to convert " << from << " to " << to EXV_WARNING << "Failed to convert " << from << " to " << to
<< ", unable to parse '" << value << "'\n"; << ", unable to parse '" << value << "'\n";
#endif #endif
return; return;
@ -570,7 +570,7 @@ namespace Exiv2 {
} }
if (!ok) { if (!ok) {
#ifndef SUPPRESS_WARNINGS #ifndef SUPPRESS_WARNINGS
std::cerr << "Warning: Failed to convert " << from << " to " << to << "\n"; EXV_WARNING << "Failed to convert " << from << " to " << to << "\n";
#endif #endif
return; return;
} }
@ -583,7 +583,7 @@ namespace Exiv2 {
if (!pos->value().ok()) { if (!pos->value().ok()) {
#ifndef SUPPRESS_WARNINGS #ifndef SUPPRESS_WARNINGS
std::cerr << "Warning: Failed to convert " << from << " to " << to << "\n"; EXV_WARNING << "Failed to convert " << from << " to " << to << "\n";
#endif #endif
return; return;
} }
@ -611,14 +611,14 @@ namespace Exiv2 {
} }
if (datePos == exifData_->end()) { if (datePos == exifData_->end()) {
#ifndef SUPPRESS_WARNINGS #ifndef SUPPRESS_WARNINGS
std::cerr << "Warning: Failed to convert " << from << " to " << to << "\n"; EXV_WARNING << "Failed to convert " << from << " to " << to << "\n";
#endif #endif
return; return;
} }
std::string value = datePos->toString(); std::string value = datePos->toString();
if (sscanf(value.c_str(), "%d:%d:%d", &year, &month, &day) != 3) { if (sscanf(value.c_str(), "%d:%d:%d", &year, &month, &day) != 3) {
#ifndef SUPPRESS_WARNINGS #ifndef SUPPRESS_WARNINGS
std::cerr << "Warning: Failed to convert " << from << " to " << to EXV_WARNING << "Failed to convert " << from << " to " << to
<< ", unable to parse '" << value << "'\n"; << ", unable to parse '" << value << "'\n";
#endif #endif
return; return;
@ -694,7 +694,7 @@ namespace Exiv2 {
int value = pos->toLong(); int value = pos->toLong();
if (!pos->value().ok()) { if (!pos->value().ok()) {
#ifndef SUPPRESS_WARNINGS #ifndef SUPPRESS_WARNINGS
std::cerr << "Warning: Failed to convert " << from << " to " << to << "\n"; EXV_WARNING << "Failed to convert " << from << " to " << to << "\n";
#endif #endif
return; return;
} }
@ -715,14 +715,14 @@ namespace Exiv2 {
if (!prepareXmpTarget(to)) return; if (!prepareXmpTarget(to)) return;
if (pos->count() != 3) { if (pos->count() != 3) {
#ifndef SUPPRESS_WARNINGS #ifndef SUPPRESS_WARNINGS
std::cerr << "Warning: Failed to convert " << from << " to " << to << "\n"; EXV_WARNING << "Failed to convert " << from << " to " << to << "\n";
#endif #endif
return; return;
} }
Exiv2::ExifData::iterator refPos = exifData_->findKey(ExifKey(std::string(from) + "Ref")); Exiv2::ExifData::iterator refPos = exifData_->findKey(ExifKey(std::string(from) + "Ref"));
if (refPos == exifData_->end()) { if (refPos == exifData_->end()) {
#ifndef SUPPRESS_WARNINGS #ifndef SUPPRESS_WARNINGS
std::cerr << "Warning: Failed to convert " << from << " to " << to << "\n"; EXV_WARNING << "Failed to convert " << from << " to " << to << "\n";
#endif #endif
return; return;
} }
@ -732,7 +732,7 @@ namespace Exiv2 {
const int32_t d = pos->toRational(i).second; const int32_t d = pos->toRational(i).second;
if (d == 0) { if (d == 0) {
#ifndef SUPPRESS_WARNINGS #ifndef SUPPRESS_WARNINGS
std::cerr << "Warning: Failed to convert " << from << " to " << to << "\n"; EXV_WARNING << "Failed to convert " << from << " to " << to << "\n";
#endif #endif
return; return;
} }
@ -760,7 +760,7 @@ namespace Exiv2 {
std::string value; std::string value;
if (!getTextValue(value, pos)) { if (!getTextValue(value, pos)) {
#ifndef SUPPRESS_WARNINGS #ifndef SUPPRESS_WARNINGS
std::cerr << "Warning: Failed to convert " << from << " to " << to << "\n"; EXV_WARNING << "Failed to convert " << from << " to " << to << "\n";
#endif #endif
return; return;
} }
@ -781,7 +781,7 @@ namespace Exiv2 {
std::string value; std::string value;
if (!getTextValue(value, pos)) { if (!getTextValue(value, pos)) {
#ifndef SUPPRESS_WARNINGS #ifndef SUPPRESS_WARNINGS
std::cerr << "Warning: Failed to convert " << from << " to " << to << "\n"; EXV_WARNING << "Failed to convert " << from << " to " << to << "\n";
#endif #endif
return; return;
} }
@ -800,7 +800,7 @@ namespace Exiv2 {
std::string value = pos->toString(i); std::string value = pos->toString(i);
if (!pos->value().ok()) { if (!pos->value().ok()) {
#ifndef SUPPRESS_WARNINGS #ifndef SUPPRESS_WARNINGS
std::cerr << "Warning: Failed to convert " << from << " to " << to << "\n"; EXV_WARNING << "Failed to convert " << from << " to " << to << "\n";
#endif #endif
return; return;
} }
@ -820,7 +820,7 @@ namespace Exiv2 {
std::string value = pos->toString(); std::string value = pos->toString();
if (!pos->value().ok()) { if (!pos->value().ok()) {
#ifndef SUPPRESS_WARNINGS #ifndef SUPPRESS_WARNINGS
std::cerr << "Warning: Failed to convert " << from << " to " << to << "\n"; EXV_WARNING << "Failed to convert " << from << " to " << to << "\n";
#endif #endif
return; return;
} }
@ -830,7 +830,7 @@ namespace Exiv2 {
} }
#ifndef SUPPRESS_WARNINGS #ifndef SUPPRESS_WARNINGS
catch (const XMP_Error& e) { catch (const XMP_Error& e) {
std::cerr << "Warning: Failed to convert " << from << " to " << to << " (" << e.GetErrMsg() << ")\n"; EXV_WARNING << "Failed to convert " << from << " to " << to << " (" << e.GetErrMsg() << ")\n";
return; return;
} }
#else #else
@ -904,7 +904,7 @@ namespace Exiv2 {
if (erase_) xmpData_->erase(pos); if (erase_) xmpData_->erase(pos);
#else #else
# ifndef SUPPRESS_WARNINGS # ifndef SUPPRESS_WARNINGS
std::cerr << "Warning: Failed to convert " << from << " to " << to << "\n"; EXV_WARNING << "Failed to convert " << from << " to " << to << "\n";
# endif # endif
#endif // !EXV_HAVE_XMP_TOOLKIT #endif // !EXV_HAVE_XMP_TOOLKIT
} }
@ -917,7 +917,7 @@ namespace Exiv2 {
std::string value = pos->toString(); std::string value = pos->toString();
if (!pos->value().ok() || value.length() < 4) { if (!pos->value().ok() || value.length() < 4) {
#ifndef SUPPRESS_WARNINGS #ifndef SUPPRESS_WARNINGS
std::cerr << "Warning: Failed to convert " << from << " to " << to << "\n"; EXV_WARNING << "Failed to convert " << from << " to " << to << "\n";
#endif #endif
return; return;
} }
@ -940,7 +940,7 @@ namespace Exiv2 {
std::string value = pos->toString(); std::string value = pos->toString();
if (!pos->value().ok()) { if (!pos->value().ok()) {
#ifndef SUPPRESS_WARNINGS #ifndef SUPPRESS_WARNINGS
std::cerr << "Warning: Failed to convert " << from << " to " << to << "\n"; EXV_WARNING << "Failed to convert " << from << " to " << to << "\n";
#endif #endif
return; return;
} }
@ -966,7 +966,7 @@ namespace Exiv2 {
value |= fired & 1; value |= fired & 1;
#ifndef SUPPRESS_WARNINGS #ifndef SUPPRESS_WARNINGS
else else
std::cerr << "Warning: Failed to convert " << std::string(from) + "/exif:Fired" << " to " << to << "\n"; EXV_WARNING << "Failed to convert " << std::string(from) + "/exif:Fired" << " to " << to << "\n";
#endif #endif
} }
pos = xmpData_->findKey(XmpKey(std::string(from) + "/exif:Return")); pos = xmpData_->findKey(XmpKey(std::string(from) + "/exif:Return"));
@ -976,7 +976,7 @@ namespace Exiv2 {
value |= (ret & 3) << 1; value |= (ret & 3) << 1;
#ifndef SUPPRESS_WARNINGS #ifndef SUPPRESS_WARNINGS
else else
std::cerr << "Warning: Failed to convert " << std::string(from) + "/exif:Return" << " to " << to << "\n"; EXV_WARNING << "Failed to convert " << std::string(from) + "/exif:Return" << " to " << to << "\n";
#endif #endif
} }
pos = xmpData_->findKey(XmpKey(std::string(from) + "/exif:Mode")); pos = xmpData_->findKey(XmpKey(std::string(from) + "/exif:Mode"));
@ -986,7 +986,7 @@ namespace Exiv2 {
value |= (mode & 3) << 3; value |= (mode & 3) << 3;
#ifndef SUPPRESS_WARNINGS #ifndef SUPPRESS_WARNINGS
else else
std::cerr << "Warning: Failed to convert " << std::string(from) + "/exif:Mode" << " to " << to << "\n"; EXV_WARNING << "Failed to convert " << std::string(from) + "/exif:Mode" << " to " << to << "\n";
#endif #endif
} }
pos = xmpData_->findKey(XmpKey(std::string(from) + "/exif:Function")); pos = xmpData_->findKey(XmpKey(std::string(from) + "/exif:Function"));
@ -996,7 +996,7 @@ namespace Exiv2 {
value |= (function & 1) << 5; value |= (function & 1) << 5;
#ifndef SUPPRESS_WARNINGS #ifndef SUPPRESS_WARNINGS
else else
std::cerr << "Warning: Failed to convert " << std::string(from) + "/exif:Function" << " to " << to << "\n"; EXV_WARNING << "Failed to convert " << std::string(from) + "/exif:Function" << " to " << to << "\n";
#endif #endif
} }
pos = xmpData_->findKey(XmpKey(std::string(from) + "/exif:RedEyeMode")); pos = xmpData_->findKey(XmpKey(std::string(from) + "/exif:RedEyeMode"));
@ -1006,7 +1006,7 @@ namespace Exiv2 {
value |= (red & 1) << 6; value |= (red & 1) << 6;
#ifndef SUPPRESS_WARNINGS #ifndef SUPPRESS_WARNINGS
else else
std::cerr << "Warning: Failed to convert " << std::string(from) + "/exif:RedEyeMode" << " to " << to << "\n"; EXV_WARNING << "Failed to convert " << std::string(from) + "/exif:RedEyeMode" << " to " << to << "\n";
#endif #endif
} }
@ -1022,13 +1022,13 @@ namespace Exiv2 {
std::string value = pos->toString(); std::string value = pos->toString();
if (!pos->value().ok()) { if (!pos->value().ok()) {
#ifndef SUPPRESS_WARNINGS #ifndef SUPPRESS_WARNINGS
std::cerr << "Warning: Failed to convert " << from << " to " << to << "\n"; EXV_WARNING << "Failed to convert " << from << " to " << to << "\n";
#endif #endif
return; return;
} }
if (value.empty()) { if (value.empty()) {
#ifndef SUPPRESS_WARNINGS #ifndef SUPPRESS_WARNINGS
std::cerr << "Warning: " << from << " is empty\n"; EXV_WARNING << from << " is empty\n";
#endif #endif
return; return;
} }
@ -1059,7 +1059,7 @@ namespace Exiv2 {
if ( in.bad() || !(ref == 'N' || ref == 'S' || ref == 'E' || ref == 'W') if ( in.bad() || !(ref == 'N' || ref == 'S' || ref == 'E' || ref == 'W')
|| sep1 != ',' || sep2 != ',' || !in.eof()) { || sep1 != ',' || sep2 != ',' || !in.eof()) {
#ifndef SUPPRESS_WARNINGS #ifndef SUPPRESS_WARNINGS
std::cerr << "Warning: Failed to convert " << from << " to " << to << "\n"; EXV_WARNING << "Failed to convert " << from << " to " << to << "\n";
#endif #endif
return; return;
} }
@ -1089,7 +1089,7 @@ namespace Exiv2 {
std::string value = pos->toString(); std::string value = pos->toString();
if (!pos->value().ok()) { if (!pos->value().ok()) {
#ifndef SUPPRESS_WARNINGS #ifndef SUPPRESS_WARNINGS
std::cerr << "Warning: Failed to convert " << from << " to " << to << "\n"; EXV_WARNING << "Failed to convert " << from << " to " << to << "\n";
#endif #endif
++pos; ++pos;
continue; continue;
@ -1115,7 +1115,7 @@ namespace Exiv2 {
std::string value; std::string value;
if (!getTextValue(value, pos)) { if (!getTextValue(value, pos)) {
#ifndef SUPPRESS_WARNINGS #ifndef SUPPRESS_WARNINGS
std::cerr << "Warning: Failed to convert " << from << " to " << to << "\n"; EXV_WARNING << "Failed to convert " << from << " to " << to << "\n";
#endif #endif
return; return;
} }
@ -1131,7 +1131,7 @@ namespace Exiv2 {
std::string value = pos->toString(i); std::string value = pos->toString(i);
if (!pos->value().ok()) { if (!pos->value().ok()) {
#ifndef SUPPRESS_WARNINGS #ifndef SUPPRESS_WARNINGS
std::cerr << "Warning: Failed to convert " << from << " to " << to << "\n"; EXV_WARNING << "Failed to convert " << from << " to " << to << "\n";
#endif #endif
continue; continue;
} }
@ -1324,7 +1324,7 @@ namespace Exiv2 {
cd = iconv_open(to, from); cd = iconv_open(to, from);
if (cd == (iconv_t)(-1)) { if (cd == (iconv_t)(-1)) {
#ifndef SUPPRESS_WARNINGS #ifndef SUPPRESS_WARNINGS
std::cerr << "Warning: iconv_open: " << strError() << "\n"; EXV_WARNING << "iconv_open: " << strError() << "\n";
#endif #endif
return false; return false;
} }
@ -1343,8 +1343,7 @@ namespace Exiv2 {
int outbytesProduced = sizeof(outbuf) - 1 - outbytesleft; int outbytesProduced = sizeof(outbuf) - 1 - outbytesleft;
if (rc == size_t(-1) && errno != E2BIG) { if (rc == size_t(-1) && errno != E2BIG) {
#ifndef SUPPRESS_WARNINGS #ifndef SUPPRESS_WARNINGS
std::cerr << "Warning: iconv: " EXV_WARNING << "iconv: " << strError()
<< strError()
<< " inbytesleft = " << inbytesleft << "\n"; << " inbytesleft = " << inbytesleft << "\n";
#endif #endif
ret = false; ret = false;

@ -34,7 +34,9 @@ EXIV2_RCSID("@(#) $Id$")
#include "i18n.h" // NLS support. #include "i18n.h" // NLS support.
// + standard includes // + standard includes
#include <iostream>
#include <string> #include <string>
#include <cassert>
// ***************************************************************************** // *****************************************************************************
namespace { namespace {
@ -111,6 +113,21 @@ namespace {
// class member definitions // class member definitions
namespace Exiv2 { namespace Exiv2 {
LogMsg::Level LogMsg::level_ = LogMsg::info; // 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::warn: std::cerr << "Warning: "; break;
case LogMsg::error: std::cerr << "Error: "; break;
case LogMsg::mute: assert(true);
}
std::cerr << s;
}
AnyError::~AnyError() throw() AnyError::~AnyError() throw()
{ {
} }

@ -20,7 +20,7 @@
*/ */
/*! /*!
@file error.hpp @file error.hpp
@brief Error class for exceptions @brief Error class for exceptions, log message class
@version $Rev$ @version $Rev$
@author Andreas Huggel (ahu) @author Andreas Huggel (ahu)
<a href="mailto:ahuggel@gmx.net">ahuggel@gmx.net</a> <a href="mailto:ahuggel@gmx.net">ahuggel@gmx.net</a>
@ -38,6 +38,7 @@
#include <exception> #include <exception>
#include <string> #include <string>
#include <iosfwd> #include <iosfwd>
#include <sstream>
// ***************************************************************************** // *****************************************************************************
// namespace extensions // namespace extensions
@ -46,6 +47,97 @@ namespace Exiv2 {
// ***************************************************************************** // *****************************************************************************
// class definitions // class definitions
/*!
@brief Class for a log message, used by the library. Applications can set
the log level and provide a customer log message handler (callback
function).
This class is meant to be used as a temporary object like this:
<code>
LogMsg(LogMsg::warn) << "Warning! Something looks fishy.\n";
</code>
The convenience macros EXV_DEBUG, EXV_INFO, EXV_WARN and EXV_ERROR
are just shorthands for the constructor calls.
*/
class EXIV2API LogMsg {
public:
/*!
@brief Defined log levels. To suppress all log messages, either set the
log level to \c mute or set the log message handler to 0.
*/
enum Level { debug = 0, info = 1, warn = 2, error = 3, mute = 4 };
/*!
@brief Type for a log message handler function. The function receives
the log level and message and can process it in an application
specific way. The default handler sends the log message to
standard error.
*/
typedef void (*Handler)(int, const char*);
//! @name Creators
//@{
//! Constructor, takes the log message type as an argument
explicit LogMsg(Level msgType) : msgType_(msgType) {}
//! Destructor, passes the log message to the message handler depending on the log level
~LogMsg() { if (msgType_ >= level_ && handler_) handler_(msgType_, os_.str().c_str()); }
//@}
//! @name Manipulators
//@{
/*!
@brief Output operator, to pass the message to a log message object.
(This is not perfect. It can deal with some std manipulators
but not all, e.g., not std::endl.)
*/
template<typename T>
LogMsg& operator<<(const T& t)
{
os_ << t;
return *this;
}
//@}
/*!
@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
level to \c mute (or set the log message handler to 0).
*/
static void setLevel(Level level) { level_ = level; }
/*!
@brief Set the log message handler. The default handler writes log
messages to standard error. To suppress all log messages, set
the log message handler to 0 (or set the log level to \c mute).
*/
static void setHandler(Handler handler) { handler_ = handler; }
//! Return the current log level
static Level level() { return level_; }
//! Return the current log message handler
static Handler handler() { return handler_; }
//! The default log handler. Sends the log message to standard error.
static void defaultHandler(int level, const char* s);
private:
// DATA
// The output level. Only messages with type >= level_ will be written
static Level level_;
// The log handler in use
static Handler handler_;
// The type of this log message
const Level msgType_;
// Holds the log message until it is passed to the message handler
std::ostringstream os_;
}; // class LogMsg
// Macros for simple access
#define EXV_DEBUG LogMsg(LogMsg::debug) //!< Shorthand for a debug log message object
#define EXV_INFO LogMsg(LogMsg::info) //!< Shorthand for an info log message object
#define EXV_WARNING LogMsg(LogMsg::warn) //!< Shorthand for a warning log message object
#define EXV_ERROR LogMsg(LogMsg::error) //!< Shorthand for an error log message object
#ifdef _MSC_VER #ifdef _MSC_VER
// Disable MSVC warnings "non - DLL-interface classkey 'identifier' used as base // Disable MSVC warnings "non - DLL-interface classkey 'identifier' used as base
// for DLL-interface classkey 'identifier'" // for DLL-interface classkey 'identifier'"

@ -634,10 +634,10 @@ namespace Exiv2 {
size); size);
#ifndef SUPPRESS_WARNINGS #ifndef SUPPRESS_WARNINGS
if (!iptcData.empty()) { if (!iptcData.empty()) {
std::cerr << "Warning: Ignoring IPTC information encoded in the Exif data.\n"; EXV_WARNING << "Ignoring IPTC information encoded in the Exif data.\n";
} }
if (!xmpData.empty()) { if (!xmpData.empty()) {
std::cerr << "Warning: Ignoring XMP information encoded in the Exif data.\n"; EXV_WARNING << "Ignoring XMP information encoded in the Exif data.\n";
} }
#endif #endif
return bo; return bo;
@ -765,7 +765,7 @@ namespace Exiv2 {
if (pos != ed.end() && sumToLong(*pos) > 32768) { if (pos != ed.end() && sumToLong(*pos) > 32768) {
delTags = true; delTags = true;
#ifndef SUPPRESS_WARNINGS #ifndef SUPPRESS_WARNINGS
std::cerr << "Warning: Exif tag " << pos->key() << " not encoded\n"; EXV_WARNING << "Exif tag " << pos->key() << " not encoded\n";
#endif #endif
ed.erase(pos); ed.erase(pos);
} }
@ -775,7 +775,7 @@ namespace Exiv2 {
pos = ed.findKey(ExifKey(filteredPvTags[i].key_)); pos = ed.findKey(ExifKey(filteredPvTags[i].key_));
if (pos != ed.end()) { if (pos != ed.end()) {
#ifndef SUPPRESS_WARNINGS #ifndef SUPPRESS_WARNINGS
std::cerr << "Warning: Exif tag " << pos->key() << " not encoded\n"; EXV_WARNING << "Exif tag " << pos->key() << " not encoded\n";
#endif #endif
ed.erase(pos); ed.erase(pos);
} }
@ -784,7 +784,7 @@ namespace Exiv2 {
case pttIfd: case pttIfd:
if (delTags) { if (delTags) {
#ifndef SUPPRESS_WARNINGS #ifndef SUPPRESS_WARNINGS
std::cerr << "Warning: Exif IFD " << filteredPvTags[i].key_ << " not encoded\n"; EXV_WARNING << "Exif IFD " << filteredPvTags[i].key_ << " not encoded\n";
#endif #endif
eraseIfd(ed, Internal::groupId(filteredPvTags[i].key_)); eraseIfd(ed, Internal::groupId(filteredPvTags[i].key_));
} }
@ -797,7 +797,7 @@ namespace Exiv2 {
if ( pos->size() > 4096 if ( pos->size() > 4096
&& pos->tagName().substr(0, 2) == "0x") { && pos->tagName().substr(0, 2) == "0x") {
#ifndef SUPPRESS_WARNINGS #ifndef SUPPRESS_WARNINGS
std::cerr << "Warning: Exif tag " << pos->key() << " not encoded\n"; EXV_WARNING << "Exif tag " << pos->key() << " not encoded\n";
#endif #endif
pos = ed.erase(pos); pos = ed.erase(pos);
} }

@ -451,8 +451,7 @@ namespace Exiv2 {
int rc = 0; int rc = 0;
if ((rc = readData(iptcData, dataSet, record, pRead, sizeData)) != 0) { if ((rc = readData(iptcData, dataSet, record, pRead, sizeData)) != 0) {
#ifndef SUPPRESS_WARNINGS #ifndef SUPPRESS_WARNINGS
std::cerr << "Warning: " EXV_WARNING << "Failed to read IPTC dataset "
<< "Failed to read IPTC dataset "
<< IptcKey(dataSet, record) << IptcKey(dataSet, record)
<< " (rc = " << rc << "); skipped.\n"; << " (rc = " << rc << "); skipped.\n";
#endif #endif
@ -460,8 +459,7 @@ namespace Exiv2 {
} }
#ifndef SUPPRESS_WARNINGS #ifndef SUPPRESS_WARNINGS
else { else {
std::cerr << "Warning: " EXV_WARNING << "IPTC dataset " << IptcKey(dataSet, record)
<< "IPTC dataset " << IptcKey(dataSet, record)
<< " has invalid size " << sizeData << "; skipped.\n"; << " has invalid size " << sizeData << "; skipped.\n";
} }
#endif #endif

@ -286,7 +286,7 @@ namespace Exiv2
else else
{ {
#ifndef SUPPRESS_WARNINGS #ifndef SUPPRESS_WARNINGS
std::cerr << "Exiv2::Jp2Image::readMetadata: Failed to decode Exif metadata.\n"; EXV_WARNING << "Failed to decode Exif metadata.\n";
#endif #endif
exifData_.clear(); exifData_.clear();
} }
@ -305,7 +305,7 @@ namespace Exiv2
if (IptcParser::decode(iptcData_, rawData.pData_, rawData.size_)) if (IptcParser::decode(iptcData_, rawData.pData_, rawData.size_))
{ {
#ifndef SUPPRESS_WARNINGS #ifndef SUPPRESS_WARNINGS
std::cerr << "Warning: Failed to decode IPTC metadata.\n"; EXV_WARNING << "Failed to decode IPTC metadata.\n";
#endif #endif
iptcData_.clear(); iptcData_.clear();
} }
@ -327,8 +327,7 @@ namespace Exiv2
if (idx != std::string::npos && idx > 0) if (idx != std::string::npos && idx > 0)
{ {
#ifndef SUPPRESS_WARNINGS #ifndef SUPPRESS_WARNINGS
std::cerr << "Exiv2::Jp2Image::readMetadata: Removing " EXV_WARNING << "Removing " << static_cast<uint32_t>(idx)
<< static_cast<uint32_t>(idx)
<< " characters from the beginning of the XMP packet\n"; << " characters from the beginning of the XMP packet\n";
#endif #endif
xmpPacket_ = xmpPacket_.substr(idx); xmpPacket_ = xmpPacket_.substr(idx);
@ -337,7 +336,7 @@ namespace Exiv2
if (xmpPacket_.size() > 0 && XmpParser::decode(xmpData_, xmpPacket_)) if (xmpPacket_.size() > 0 && XmpParser::decode(xmpData_, xmpPacket_))
{ {
#ifndef SUPPRESS_WARNINGS #ifndef SUPPRESS_WARNINGS
std::cerr << "Exiv2::Jp2Image::readMetadata: Failed to decode XMP metadata.\n"; EXV_WARNING << "Failed to decode XMP metadata.\n";
#endif #endif
} }
} }
@ -532,7 +531,7 @@ namespace Exiv2
if (XmpParser::encode(xmpPacket_, xmpData_) > 1) if (XmpParser::encode(xmpPacket_, xmpData_) > 1)
{ {
#ifndef SUPPRESS_WARNINGS #ifndef SUPPRESS_WARNINGS
std::cerr << "Error: Failed to encode XMP metadata.\n"; EXV_ERROR << "Failed to encode XMP metadata.\n";
#endif #endif
} }
} }

@ -347,7 +347,7 @@ namespace Exiv2 {
setByteOrder(bo); setByteOrder(bo);
if (rawExif.size_ > 0 && byteOrder() == invalidByteOrder) { if (rawExif.size_ > 0 && byteOrder() == invalidByteOrder) {
#ifndef SUPPRESS_WARNINGS #ifndef SUPPRESS_WARNINGS
std::cerr << "Warning: Failed to decode Exif metadata.\n"; EXV_WARNING << "Failed to decode Exif metadata.\n";
#endif #endif
exifData_.clear(); exifData_.clear();
} }
@ -368,7 +368,7 @@ namespace Exiv2 {
xmpPacket_.assign(reinterpret_cast<char*>(xmpPacket.pData_), xmpPacket.size_); xmpPacket_.assign(reinterpret_cast<char*>(xmpPacket.pData_), xmpPacket.size_);
if (xmpPacket_.size() > 0 && XmpParser::decode(xmpData_, xmpPacket_)) { if (xmpPacket_.size() > 0 && XmpParser::decode(xmpData_, xmpPacket_)) {
#ifndef SUPPRESS_WARNINGS #ifndef SUPPRESS_WARNINGS
std::cerr << "Warning: Failed to decode XMP metadata.\n"; EXV_WARNING << "Failed to decode XMP metadata.\n";
#endif #endif
} }
--search; --search;
@ -474,7 +474,7 @@ namespace Exiv2 {
&iptcBlob[0], &iptcBlob[0],
static_cast<uint32_t>(iptcBlob.size()))) { static_cast<uint32_t>(iptcBlob.size()))) {
#ifndef SUPPRESS_WARNINGS #ifndef SUPPRESS_WARNINGS
std::cerr << "Warning: Failed to decode IPTC metadata.\n"; EXV_WARNING << "Failed to decode IPTC metadata.\n";
#endif #endif
iptcData_.clear(); iptcData_.clear();
} }
@ -482,7 +482,7 @@ namespace Exiv2 {
if (rc != 0) { if (rc != 0) {
#ifndef SUPPRESS_WARNINGS #ifndef SUPPRESS_WARNINGS
std::cerr << "Warning: JPEG format error, rc = " << rc << "\n"; EXV_WARNING << "JPEG format error, rc = " << rc << "\n";
#endif #endif
} }
} // JpegBase::readMetadata } // JpegBase::readMetadata
@ -698,7 +698,7 @@ namespace Exiv2 {
if (writeXmpFromPacket() == false) { if (writeXmpFromPacket() == false) {
if (XmpParser::encode(xmpPacket_, xmpData_, XmpParser::useCompactFormat | XmpParser::omitAllFormatting) > 1) { if (XmpParser::encode(xmpPacket_, xmpData_, XmpParser::useCompactFormat | XmpParser::omitAllFormatting) > 1) {
#ifndef SUPPRESS_WARNINGS #ifndef SUPPRESS_WARNINGS
std::cerr << "Error: Failed to encode XMP metadata.\n"; EXV_ERROR << "Failed to encode XMP metadata.\n";
#endif #endif
} }
} }

@ -276,7 +276,7 @@ namespace Exiv2 {
else else
{ {
#ifndef SUPPRESS_WARNINGS #ifndef SUPPRESS_WARNINGS
std::cerr << "Exiv2::PngChunk::parseChunkContent: Failed to decode Exif metadata.\n"; EXV_WARNING << "Failed to decode Exif metadata.\n";
#endif #endif
pImage->exifData().clear(); pImage->exifData().clear();
} }
@ -317,7 +317,7 @@ namespace Exiv2 {
&iptcBlob[0], &iptcBlob[0],
static_cast<uint32_t>(iptcBlob.size()))) { static_cast<uint32_t>(iptcBlob.size()))) {
#ifndef SUPPRESS_WARNINGS #ifndef SUPPRESS_WARNINGS
std::cerr << "Warning: Failed to decode IPTC metadata.\n"; EXV_WARNING << "Failed to decode IPTC metadata.\n";
#endif #endif
pImage->clearIptcData(); pImage->clearIptcData();
} }
@ -327,7 +327,7 @@ namespace Exiv2 {
psData.pData_, psData.pData_,
psData.size_)) { psData.size_)) {
#ifndef SUPPRESS_WARNINGS #ifndef SUPPRESS_WARNINGS
std::cerr << "Warning: Failed to decode IPTC metadata.\n"; EXV_WARNING << "Failed to decode IPTC metadata.\n";
#endif #endif
pImage->clearIptcData(); pImage->clearIptcData();
} }
@ -351,7 +351,7 @@ namespace Exiv2 {
if (idx != std::string::npos && idx > 0) if (idx != std::string::npos && idx > 0)
{ {
#ifndef SUPPRESS_WARNINGS #ifndef SUPPRESS_WARNINGS
std::cerr << "Exiv2::PngChunk::parseChunkContent: Removing " << idx EXV_WARNING << "Removing " << idx
<< " characters from the beginning of the XMP packet\n"; << " characters from the beginning of the XMP packet\n";
#endif #endif
xmpPacket = xmpPacket.substr(idx); xmpPacket = xmpPacket.substr(idx);
@ -359,7 +359,7 @@ namespace Exiv2 {
if (XmpParser::decode(pImage->xmpData(), xmpPacket)) if (XmpParser::decode(pImage->xmpData(), xmpPacket))
{ {
#ifndef SUPPRESS_WARNINGS #ifndef SUPPRESS_WARNINGS
std::cerr << "Exiv2::PngChunk::parseChunkContent: Failed to decode XMP metadata.\n"; EXV_WARNING << "Failed to decode XMP metadata.\n";
#endif #endif
} }
} }
@ -379,7 +379,7 @@ namespace Exiv2 {
if (idx != std::string::npos && idx > 0) if (idx != std::string::npos && idx > 0)
{ {
#ifndef SUPPRESS_WARNINGS #ifndef SUPPRESS_WARNINGS
std::cerr << "Warning: Removing " << idx << " characters " EXV_WARNING << "Removing " << idx << " characters "
<< "from the beginning of the XMP packet\n"; << "from the beginning of the XMP packet\n";
#endif #endif
xmpPacket = xmpPacket.substr(idx); xmpPacket = xmpPacket.substr(idx);
@ -387,7 +387,7 @@ namespace Exiv2 {
if (XmpParser::decode(pImage->xmpData(), xmpPacket)) if (XmpParser::decode(pImage->xmpData(), xmpPacket))
{ {
#ifndef SUPPRESS_WARNINGS #ifndef SUPPRESS_WARNINGS
std::cerr << "Warning: Failed to decode XMP metadata.\n"; EXV_WARNING << "Failed to decode XMP metadata.\n";
#endif #endif
} }
} }

@ -325,7 +325,7 @@ namespace Exiv2 {
if (writeXmpFromPacket() == false) { if (writeXmpFromPacket() == false) {
if (XmpParser::encode(xmpPacket_, xmpData_) > 1) { if (XmpParser::encode(xmpPacket_, xmpData_) > 1) {
#ifndef SUPPRESS_WARNINGS #ifndef SUPPRESS_WARNINGS
std::cerr << "Error: Failed to encode XMP metadata.\n"; EXV_ERROR << "Failed to encode XMP metadata.\n";
#endif #endif
} }
} }

@ -418,7 +418,7 @@ namespace {
} }
catch (const AnyError& /* error */ ) { catch (const AnyError& /* error */ ) {
#ifndef SUPPRESS_WARNINGS #ifndef SUPPRESS_WARNINGS
std::cerr << "Warning: Invalid JPEG preview image.\n"; EXV_WARNING << "Invalid JPEG preview image.\n";
#endif #endif
return false; return false;
} }

@ -259,7 +259,7 @@ namespace Exiv2 {
if (io_->error() || io_->eof()) throw Error(14); if (io_->error() || io_->eof()) throw Error(14);
if (IptcParser::decode(iptcData_, rawIPTC.pData_, rawIPTC.size_)) { if (IptcParser::decode(iptcData_, rawIPTC.pData_, rawIPTC.size_)) {
#ifndef SUPPRESS_WARNINGS #ifndef SUPPRESS_WARNINGS
std::cerr << "Warning: Failed to decode IPTC metadata.\n"; EXV_WARNING << "Failed to decode IPTC metadata.\n";
#endif #endif
iptcData_.clear(); iptcData_.clear();
} }
@ -275,7 +275,7 @@ namespace Exiv2 {
setByteOrder(bo); setByteOrder(bo);
if (rawExif.size_ > 0 && byteOrder() == invalidByteOrder) { if (rawExif.size_ > 0 && byteOrder() == invalidByteOrder) {
#ifndef SUPPRESS_WARNINGS #ifndef SUPPRESS_WARNINGS
std::cerr << "Warning: Failed to decode Exif metadata.\n"; EXV_WARNING << "Failed to decode Exif metadata.\n";
#endif #endif
exifData_.clear(); exifData_.clear();
} }
@ -290,7 +290,7 @@ namespace Exiv2 {
xmpPacket_.assign(reinterpret_cast<char *>(xmpPacket.pData_), xmpPacket.size_); xmpPacket_.assign(reinterpret_cast<char *>(xmpPacket.pData_), xmpPacket.size_);
if (xmpPacket_.size() > 0 && XmpParser::decode(xmpData_, xmpPacket_)) { if (xmpPacket_.size() > 0 && XmpParser::decode(xmpData_, xmpPacket_)) {
#ifndef SUPPRESS_WARNINGS #ifndef SUPPRESS_WARNINGS
std::cerr << "Warning: Failed to decode XMP metadata.\n"; EXV_WARNING << "Failed to decode XMP metadata.\n";
#endif #endif
} }
break; break;
@ -608,7 +608,7 @@ namespace Exiv2 {
if (writeXmpFromPacket() == false) { if (writeXmpFromPacket() == false) {
if (XmpParser::encode(xmpPacket, xmpData) > 1) { if (XmpParser::encode(xmpPacket, xmpData) > 1) {
#ifndef SUPPRESS_WARNINGS #ifndef SUPPRESS_WARNINGS
std::cerr << "Error: Failed to encode XMP metadata.\n"; EXV_ERROR << "Failed to encode XMP metadata.\n";
#endif #endif
} }
} }

@ -134,7 +134,7 @@ namespace Exiv2 {
// Todo: What if there are more preview images? // Todo: What if there are more preview images?
if (list.size() > 1) { if (list.size() > 1) {
#ifndef SUPPRESS_WARNINGS #ifndef SUPPRESS_WARNINGS
std::cerr << "Warning: RW2 image contains more than one preview. None used.\n"; EXV_WARNING << "RW2 image contains more than one preview. None used.\n";
#endif #endif
} }
if (list.size() != 1) return; if (list.size() != 1) return;
@ -143,7 +143,7 @@ namespace Exiv2 {
Image::AutoPtr image = ImageFactory::open(preview.pData(), preview.size()); Image::AutoPtr image = ImageFactory::open(preview.pData(), preview.size());
if (image.get() == 0) { if (image.get() == 0) {
#ifndef SUPPRESS_WARNINGS #ifndef SUPPRESS_WARNINGS
std::cerr << "Warning: Failed to open RW2 preview image.\n"; EXV_WARNING << "Failed to open RW2 preview image.\n";
#endif #endif
return; return;
} }

@ -2084,7 +2084,7 @@ namespace Exiv2 {
cd = iconv_open("UTF-8", "UCS-2LE"); cd = iconv_open("UTF-8", "UCS-2LE");
if (cd == (iconv_t)(-1)) { if (cd == (iconv_t)(-1)) {
#ifndef SUPPRESS_WARNINGS #ifndef SUPPRESS_WARNINGS
std::cerr << "Warning: iconv_open: " << strError() << "\n"; EXV_WARNING << "iconv_open: " << strError() << "\n";
#endif #endif
go = false; go = false;
} }
@ -2106,8 +2106,7 @@ namespace Exiv2 {
&outbytesleft); &outbytesleft);
if (rc == size_t(-1)) { if (rc == size_t(-1)) {
#ifndef SUPPRESS_WARNINGS #ifndef SUPPRESS_WARNINGS
std::cerr << "Warning: iconv: " EXV_WARNING << "iconv: " << strError()
<< strError()
<< " inbytesleft = " << inbytesleft << "\n"; << " inbytesleft = " << inbytesleft << "\n";
#endif #endif
go = false; go = false;

@ -399,8 +399,7 @@ namespace Exiv2 {
{ {
if (!pValue() || !pSize) { if (!pValue() || !pSize) {
#ifndef SUPPRESS_WARNINGS #ifndef SUPPRESS_WARNINGS
std::cerr << "Warning: " EXV_WARNING << "Directory " << groupName(group())
<< "Directory " << groupName(group())
<< ", entry 0x" << std::setw(4) << ", entry 0x" << std::setw(4)
<< std::setfill('0') << std::hex << tag() << std::setfill('0') << std::hex << tag()
<< ": Size or data offset value not set, ignoring them.\n"; << ": Size or data offset value not set, ignoring them.\n";
@ -409,8 +408,7 @@ namespace Exiv2 {
} }
if (pValue()->count() == 0) { if (pValue()->count() == 0) {
#ifndef SUPPRESS_WARNINGS #ifndef SUPPRESS_WARNINGS
std::cerr << "Warning: " EXV_WARNING << "Directory " << groupName(group())
<< "Directory " << groupName(group())
<< ", entry 0x" << std::setw(4) << ", entry 0x" << std::setw(4)
<< std::setfill('0') << std::hex << tag() << std::setfill('0') << std::hex << tag()
<< ": Data offset entry value is empty, ignoring it.\n"; << ": Data offset entry value is empty, ignoring it.\n";
@ -419,8 +417,7 @@ namespace Exiv2 {
} }
if (pValue()->count() != pSize->count()) { if (pValue()->count() != pSize->count()) {
#ifndef SUPPRESS_WARNINGS #ifndef SUPPRESS_WARNINGS
std::cerr << "Warning: " EXV_WARNING << "Directory " << groupName(group())
<< "Directory " << groupName(group())
<< ", entry 0x" << std::setw(4) << ", entry 0x" << std::setw(4)
<< std::setfill('0') << std::hex << tag() << std::setfill('0') << std::hex << tag()
<< ": Size and data offset entries have different" << ": Size and data offset entries have different"
@ -439,8 +436,7 @@ namespace Exiv2 {
+ static_cast<uint32_t>(pSize->toLong(pSize->count()-1)) + static_cast<uint32_t>(pSize->toLong(pSize->count()-1))
- offset != size) { - offset != size) {
#ifndef SUPPRESS_WARNINGS #ifndef SUPPRESS_WARNINGS
std::cerr << "Warning: " EXV_WARNING << "Directory " << groupName(group())
<< "Directory " << groupName(group())
<< ", entry 0x" << std::setw(4) << ", entry 0x" << std::setw(4)
<< std::setfill('0') << std::hex << tag() << std::setfill('0') << std::hex << tag()
<< ": Data area is not contiguous, ignoring it.\n"; << ": Data area is not contiguous, ignoring it.\n";
@ -451,8 +447,7 @@ namespace Exiv2 {
|| size > sizeData || size > sizeData
|| baseOffset + offset > sizeData - size) { || baseOffset + offset > sizeData - size) {
#ifndef SUPPRESS_WARNINGS #ifndef SUPPRESS_WARNINGS
std::cerr << "Warning: " EXV_WARNING << "Directory " << groupName(group())
<< "Directory " << groupName(group())
<< ", entry 0x" << std::setw(4) << ", entry 0x" << std::setw(4)
<< std::setfill('0') << std::hex << tag() << std::setfill('0') << std::hex << tag()
<< ": Data area exceeds data buffer, ignoring it.\n"; << ": Data area exceeds data buffer, ignoring it.\n";
@ -471,8 +466,7 @@ namespace Exiv2 {
{ {
if (!pValue() || !pSize) { if (!pValue() || !pSize) {
#ifndef SUPPRESS_WARNINGS #ifndef SUPPRESS_WARNINGS
std::cerr << "Warning: " EXV_WARNING << "Directory " << groupName(group())
<< "Directory " << groupName(group())
<< ", entry 0x" << std::setw(4) << ", entry 0x" << std::setw(4)
<< std::setfill('0') << std::hex << tag() << std::setfill('0') << std::hex << tag()
<< ": Size or data offset value not set, ignoring them.\n"; << ": Size or data offset value not set, ignoring them.\n";
@ -481,8 +475,7 @@ namespace Exiv2 {
} }
if (pValue()->count() != pSize->count()) { if (pValue()->count() != pSize->count()) {
#ifndef SUPPRESS_WARNINGS #ifndef SUPPRESS_WARNINGS
std::cerr << "Warning: " EXV_WARNING << "Directory " << groupName(group())
<< "Directory " << groupName(group())
<< ", entry 0x" << std::setw(4) << ", entry 0x" << std::setw(4)
<< std::setfill('0') << std::hex << tag() << std::setfill('0') << std::hex << tag()
<< ": Size and data offset entries have different" << ": Size and data offset entries have different"
@ -499,8 +492,7 @@ namespace Exiv2 {
|| size > sizeData || size > sizeData
|| baseOffset + offset > sizeData - size) { || baseOffset + offset > sizeData - size) {
#ifndef SUPPRESS_WARNINGS #ifndef SUPPRESS_WARNINGS
std::cerr << "Warning: " EXV_WARNING << "Directory " << groupName(group())
<< "Directory " << groupName(group())
<< ", entry 0x" << std::setw(4) << ", entry 0x" << std::setw(4)
<< std::setfill('0') << std::hex << tag() << std::setfill('0') << std::hex << tag()
<< ": Strip " << std::dec << i << ": Strip " << std::dec << i
@ -1824,7 +1816,7 @@ namespace Exiv2 {
{ {
if (static_cast<uint32_t>(typeId) > 0xffff) { if (static_cast<uint32_t>(typeId) > 0xffff) {
#ifndef SUPPRESS_WARNINGS #ifndef SUPPRESS_WARNINGS
std::cerr << "Error: '" << TypeInfo::typeName(typeId) EXV_ERROR << "'" << TypeInfo::typeName(typeId)
<< "' is not a valid Exif (TIFF) type; using type '" << "' is not a valid Exif (TIFF) type; using type '"
<< TypeInfo::typeName(undefined) << "'.\n"; << TypeInfo::typeName(undefined) << "'.\n";
#endif #endif

@ -404,14 +404,14 @@ namespace Exiv2 {
std::string::size_type idx = xmpPacket.find_first_of('<'); std::string::size_type idx = xmpPacket.find_first_of('<');
if (idx != std::string::npos && idx > 0) { if (idx != std::string::npos && idx > 0) {
#ifndef SUPPRESS_WARNINGS #ifndef SUPPRESS_WARNINGS
std::cerr << "Warning: Removing " << static_cast<unsigned long>(idx) EXV_WARNING << "Removing " << static_cast<unsigned long>(idx)
<< " characters from the beginning of the XMP packet\n"; << " characters from the beginning of the XMP packet\n";
#endif #endif
xmpPacket = xmpPacket.substr(idx); xmpPacket = xmpPacket.substr(idx);
} }
if (XmpParser::decode(xmpData_, xmpPacket)) { if (XmpParser::decode(xmpData_, xmpPacket)) {
#ifndef SUPPRESS_WARNINGS #ifndef SUPPRESS_WARNINGS
std::cerr << "Warning: Failed to decode XMP metadata.\n"; EXV_WARNING << "Failed to decode XMP metadata.\n";
#endif #endif
} }
} }
@ -438,7 +438,7 @@ namespace Exiv2 {
} }
#ifndef SUPPRESS_WARNINGS #ifndef SUPPRESS_WARNINGS
else { else {
std::cerr << "Warning: Failed to decode IPTC block found in " EXV_WARNING << "Failed to decode IPTC block found in "
<< "Directory Image, entry 0x83bb\n"; << "Directory Image, entry 0x83bb\n";
} }
#endif #endif
@ -462,7 +462,7 @@ namespace Exiv2 {
} }
#ifndef SUPPRESS_WARNINGS #ifndef SUPPRESS_WARNINGS
else { else {
std::cerr << "Warning: Failed to decode IPTC block found in " EXV_WARNING << "Failed to decode IPTC block found in "
<< "Directory Image, entry 0x8649\n"; << "Directory Image, entry 0x8649\n";
} }
#endif #endif
@ -624,7 +624,7 @@ namespace Exiv2 {
std::string xmpPacket; std::string xmpPacket;
if (XmpParser::encode(xmpPacket, xmpData_) > 1) { if (XmpParser::encode(xmpPacket, xmpData_) > 1) {
#ifndef SUPPRESS_WARNINGS #ifndef SUPPRESS_WARNINGS
std::cerr << "Error: Failed to encode XMP metadata.\n"; EXV_ERROR << "Failed to encode XMP metadata.\n";
#endif #endif
} }
if (!xmpPacket.empty()) { if (!xmpPacket.empty()) {
@ -942,7 +942,7 @@ namespace Exiv2 {
const byte* zero = 0; const byte* zero = 0;
if (pos == exifData_.end()) { if (pos == exifData_.end()) {
#ifndef SUPPRESS_WARNINGS #ifndef SUPPRESS_WARNINGS
std::cerr << "Error: Size tag " << key EXV_ERROR << "Size tag " << key
<< " not found. Writing only one strip.\n"; << " not found. Writing only one strip.\n";
#endif #endif
object->strips_.clear(); object->strips_.clear();
@ -959,7 +959,7 @@ namespace Exiv2 {
if (sizeTotal != sizeDataArea) { if (sizeTotal != sizeDataArea) {
#ifndef SUPPRESS_WARNINGS #ifndef SUPPRESS_WARNINGS
ExifKey key2(object->tag(), groupName(object->group())); ExifKey key2(object->tag(), groupName(object->group()));
std::cerr << "Error: Sum of all sizes of " << key EXV_ERROR << "Sum of all sizes of " << key
<< " != data size of " << key2 << ". " << " != data size of " << key2 << ". "
<< "This results in an invalid image.\n"; << "This results in an invalid image.\n";
#endif #endif
@ -984,7 +984,7 @@ namespace Exiv2 {
#ifndef SUPPRESS_WARNINGS #ifndef SUPPRESS_WARNINGS
else { else {
ExifKey key2(object->tag(), groupName(object->group())); ExifKey key2(object->tag(), groupName(object->group()));
std::cerr << "Warning: No image data to encode " << key2 << ".\n"; EXV_WARNING << "No image data to encode " << key2 << ".\n";
} }
#endif #endif
} }
@ -1227,8 +1227,7 @@ namespace Exiv2 {
DirList::const_iterator pos = dirList_.find(start); DirList::const_iterator pos = dirList_.find(start);
if (pos != dirList_.end()) { if (pos != dirList_.end()) {
#ifndef SUPPRESS_WARNINGS #ifndef SUPPRESS_WARNINGS
std::cerr << "Error: " EXV_ERROR << groupName(group) << " pointer references previously read "
<< groupName(group) << " pointer references previously read "
<< groupName(pos->second) << " directory. Ignored.\n"; << groupName(pos->second) << " directory. Ignored.\n";
#endif #endif
return true; return true;
@ -1262,8 +1261,7 @@ namespace Exiv2 {
if (p + 2 > pLast_) { if (p + 2 > pLast_) {
#ifndef SUPPRESS_WARNINGS #ifndef SUPPRESS_WARNINGS
std::cerr << "Error: " EXV_ERROR << "Directory " << groupName(object->group())
<< "Directory " << groupName(object->group())
<< ": IFD exceeds data buffer, cannot read entry count.\n"; << ": IFD exceeds data buffer, cannot read entry count.\n";
#endif #endif
return; return;
@ -1273,8 +1271,7 @@ namespace Exiv2 {
// Sanity check with an "unreasonably" large number // Sanity check with an "unreasonably" large number
if (n > 256) { if (n > 256) {
#ifndef SUPPRESS_WARNINGS #ifndef SUPPRESS_WARNINGS
std::cerr << "Error: " EXV_ERROR << "Directory " << groupName(object->group()) << " with "
<< "Directory " << groupName(object->group()) << " with "
<< n << " entries considered invalid; not read.\n"; << n << " entries considered invalid; not read.\n";
#endif #endif
return; return;
@ -1282,8 +1279,7 @@ namespace Exiv2 {
for (uint16_t i = 0; i < n; ++i) { for (uint16_t i = 0; i < n; ++i) {
if (p + 12 > pLast_) { if (p + 12 > pLast_) {
#ifndef SUPPRESS_WARNINGS #ifndef SUPPRESS_WARNINGS
std::cerr << "Error: " EXV_ERROR << "Directory " << groupName(object->group())
<< "Directory " << groupName(object->group())
<< ": IFD entry " << i << ": IFD entry " << i
<< " lies outside of the data buffer.\n"; << " lies outside of the data buffer.\n";
#endif #endif
@ -1302,8 +1298,7 @@ namespace Exiv2 {
if (object->hasNext()) { if (object->hasNext()) {
if (p + 4 > pLast_) { if (p + 4 > pLast_) {
#ifndef SUPPRESS_WARNINGS #ifndef SUPPRESS_WARNINGS
std::cerr << "Error: " EXV_ERROR << "Directory " << groupName(object->group())
<< "Directory " << groupName(object->group())
<< ": IFD exceeds data buffer, cannot read next pointer.\n"; << ": IFD exceeds data buffer, cannot read next pointer.\n";
#endif #endif
return; return;
@ -1314,8 +1309,7 @@ namespace Exiv2 {
tc = TiffCreator::create(Tag::next, object->group()); tc = TiffCreator::create(Tag::next, object->group());
#ifndef SUPPRESS_WARNINGS #ifndef SUPPRESS_WARNINGS
if (tc.get() == 0) { if (tc.get() == 0) {
std::cerr << "Warning: " EXV_WARNING << "Directory " << groupName(object->group())
<< "Directory " << groupName(object->group())
<< " has an unhandled next pointer.\n"; << " has an unhandled next pointer.\n";
} }
#endif #endif
@ -1323,8 +1317,7 @@ namespace Exiv2 {
if (tc.get()) { if (tc.get()) {
if (baseOffset() + next > size_) { if (baseOffset() + next > size_) {
#ifndef SUPPRESS_WARNINGS #ifndef SUPPRESS_WARNINGS
std::cerr << "Error: " EXV_ERROR << "Directory " << groupName(object->group())
<< "Directory " << groupName(object->group())
<< ": Next pointer is out of bounds; ignored.\n"; << ": Next pointer is out of bounds; ignored.\n";
#endif #endif
return; return;
@ -1349,8 +1342,7 @@ namespace Exiv2 {
if ( baseOffset() + offset > size_ if ( baseOffset() + offset > size_
|| static_cast<int32_t>(baseOffset()) + offset < 0) { || static_cast<int32_t>(baseOffset()) + offset < 0) {
#ifndef SUPPRESS_WARNINGS #ifndef SUPPRESS_WARNINGS
std::cerr << "Error: " EXV_ERROR << "Directory " << groupName(object->group())
<< "Directory " << groupName(object->group())
<< ", entry 0x" << std::setw(4) << ", entry 0x" << std::setw(4)
<< std::setfill('0') << std::hex << object->tag() << std::setfill('0') << std::hex << object->tag()
<< " Sub-IFD pointer " << i << " Sub-IFD pointer " << i
@ -1360,8 +1352,7 @@ namespace Exiv2 {
} }
if (object->newGroup_ + i == subImage9Id + 1) { if (object->newGroup_ + i == subImage9Id + 1) {
#ifndef SUPPRESS_WARNINGS #ifndef SUPPRESS_WARNINGS
std::cerr << "Warning: " EXV_WARNING << "Directory " << groupName(object->group())
<< "Directory " << groupName(object->group())
<< ", entry 0x" << std::setw(4) << ", entry 0x" << std::setw(4)
<< std::setfill('0') << std::hex << object->tag() << std::setfill('0') << std::hex << object->tag()
<< ": Skipping sub-IFDs beyond the first " << i << ".\n"; << ": Skipping sub-IFDs beyond the first " << i << ".\n";
@ -1377,8 +1368,7 @@ namespace Exiv2 {
} }
#ifndef SUPPRESS_WARNINGS #ifndef SUPPRESS_WARNINGS
else { else {
std::cerr << "Warning: " EXV_WARNING << "Directory " << groupName(object->group())
<< "Directory " << groupName(object->group())
<< ", entry 0x" << std::setw(4) << ", entry 0x" << std::setw(4)
<< std::setfill('0') << std::hex << object->tag() << std::setfill('0') << std::hex << object->tag()
<< " doesn't look like a sub-IFD.\n"; << " doesn't look like a sub-IFD.\n";
@ -1421,7 +1411,7 @@ namespace Exiv2 {
static_cast<uint32_t>(pLast_ - object->start()), static_cast<uint32_t>(pLast_ - object->start()),
byteOrder())) { byteOrder())) {
#ifndef SUPPRESS_WARNINGS #ifndef SUPPRESS_WARNINGS
std::cerr << "Error: Failed to read " EXV_ERROR << "Failed to read "
<< groupName(object->ifd_.group()) << groupName(object->ifd_.group())
<< " IFD Makernote header.\n"; << " IFD Makernote header.\n";
#ifdef DEBUG #ifdef DEBUG
@ -1460,7 +1450,7 @@ namespace Exiv2 {
if (p + 12 > pLast_) { if (p + 12 > pLast_) {
#ifndef SUPPRESS_WARNINGS #ifndef SUPPRESS_WARNINGS
std::cerr << "Error: Entry in directory " << groupName(object->group()) EXV_ERROR << "Entry in directory " << groupName(object->group())
<< "requests access to memory beyond the data buffer. " << "requests access to memory beyond the data buffer. "
<< "Skipping entry.\n"; << "Skipping entry.\n";
#endif #endif
@ -1473,7 +1463,7 @@ namespace Exiv2 {
long typeSize = TypeInfo::typeSize(typeId); long typeSize = TypeInfo::typeSize(typeId);
if (0 == typeSize) { if (0 == typeSize) {
#ifndef SUPPRESS_WARNINGS #ifndef SUPPRESS_WARNINGS
std::cerr << "Warning: Directory " << groupName(object->group()) EXV_WARNING << "Directory " << groupName(object->group())
<< ", entry 0x" << std::setw(4) << ", entry 0x" << std::setw(4)
<< std::setfill('0') << std::hex << object->tag() << std::setfill('0') << std::hex << object->tag()
<< " has unknown Exif (TIFF) type " << std::dec << tiffType << " has unknown Exif (TIFF) type " << std::dec << tiffType
@ -1485,7 +1475,7 @@ namespace Exiv2 {
uint32_t count = getULong(p, byteOrder()); uint32_t count = getULong(p, byteOrder());
if (count >= 0x10000000) { if (count >= 0x10000000) {
#ifndef SUPPRESS_WARNINGS #ifndef SUPPRESS_WARNINGS
std::cerr << "Error: Directory " << groupName(object->group()) EXV_ERROR << "Directory " << groupName(object->group())
<< ", entry 0x" << std::setw(4) << ", entry 0x" << std::setw(4)
<< std::setfill('0') << std::hex << object->tag() << std::setfill('0') << std::hex << object->tag()
<< " has invalid size " << " has invalid size "
@ -1502,8 +1492,7 @@ namespace Exiv2 {
&& ( baseOffset() + offset >= size_ && ( baseOffset() + offset >= size_
|| static_cast<int32_t>(baseOffset()) + offset <= 0)) { || static_cast<int32_t>(baseOffset()) + offset <= 0)) {
#ifndef SUPPRESS_WARNINGS #ifndef SUPPRESS_WARNINGS
std::cerr << "Error: Offset of " EXV_ERROR << "Offset of directory " << groupName(object->group())
<< "directory " << groupName(object->group())
<< ", entry 0x" << std::setw(4) << ", entry 0x" << std::setw(4)
<< std::setfill('0') << std::hex << object->tag() << std::setfill('0') << std::hex << object->tag()
<< " is out of bounds: " << " is out of bounds: "
@ -1517,7 +1506,7 @@ namespace Exiv2 {
pData = const_cast<byte*>(pData_) + baseOffset() + offset; pData = const_cast<byte*>(pData_) + baseOffset() + offset;
if (size > static_cast<uint32_t>(pLast_ - pData)) { if (size > static_cast<uint32_t>(pLast_ - pData)) {
#ifndef SUPPRESS_WARNINGS #ifndef SUPPRESS_WARNINGS
std::cerr << "Error: Upper boundary of data for " EXV_ERROR << "Upper boundary of data for "
<< "directory " << groupName(object->group()) << "directory " << groupName(object->group())
<< ", entry 0x" << std::setw(4) << ", entry 0x" << std::setw(4)
<< std::setfill('0') << std::hex << object->tag() << std::setfill('0') << std::hex << object->tag()

@ -473,7 +473,7 @@ namespace Exiv2 {
charsetId = CharsetInfo::charsetIdByName(name); charsetId = CharsetInfo::charsetIdByName(name);
if (charsetId == invalidCharsetId) { if (charsetId == invalidCharsetId) {
#ifndef SUPPRESS_WARNINGS #ifndef SUPPRESS_WARNINGS
std::cerr << "Warning: " << Error(28, name) << "\n"; EXV_WARNING << Error(28, name) << "\n";
#endif #endif
return 1; return 1;
} }
@ -925,7 +925,7 @@ namespace Exiv2 {
// Hard coded to read Iptc style dates // Hard coded to read Iptc style dates
if (len != 8) { if (len != 8) {
#ifndef SUPPRESS_WARNINGS #ifndef SUPPRESS_WARNINGS
std::cerr << "Warning: " << Error(29) << "\n"; EXV_WARNING << Error(29) << "\n";
#endif #endif
return 1; return 1;
} }
@ -936,7 +936,7 @@ namespace Exiv2 {
&date_.year, &date_.month, &date_.day); &date_.year, &date_.month, &date_.day);
if (scanned != 3) { if (scanned != 3) {
#ifndef SUPPRESS_WARNINGS #ifndef SUPPRESS_WARNINGS
std::cerr << "Warning: " << Error(29) << "\n"; EXV_WARNING << Error(29) << "\n";
#endif #endif
return 1; return 1;
} }
@ -948,7 +948,7 @@ namespace Exiv2 {
// Hard coded to read Iptc style dates // Hard coded to read Iptc style dates
if (buf.length() < 8) { if (buf.length() < 8) {
#ifndef SUPPRESS_WARNINGS #ifndef SUPPRESS_WARNINGS
std::cerr << "Warning: " << Error(29) << "\n"; EXV_WARNING << Error(29) << "\n";
#endif #endif
return 1; return 1;
} }
@ -956,7 +956,7 @@ namespace Exiv2 {
&date_.year, &date_.month, &date_.day); &date_.year, &date_.month, &date_.day);
if (scanned != 3) { if (scanned != 3) {
#ifndef SUPPRESS_WARNINGS #ifndef SUPPRESS_WARNINGS
std::cerr << "Warning: " << Error(29) << "\n"; EXV_WARNING << Error(29) << "\n";
#endif #endif
return 1; return 1;
} }
@ -1071,7 +1071,7 @@ namespace Exiv2 {
if (rc) { if (rc) {
rc = 1; rc = 1;
#ifndef SUPPRESS_WARNINGS #ifndef SUPPRESS_WARNINGS
std::cerr << "Warning: " << Error(30) << "\n"; EXV_WARNING << Error(30) << "\n";
#endif #endif
} }
return rc; return rc;
@ -1091,7 +1091,7 @@ namespace Exiv2 {
if (rc) { if (rc) {
rc = 1; rc = 1;
#ifndef SUPPRESS_WARNINGS #ifndef SUPPRESS_WARNINGS
std::cerr << "Warning: " << Error(30) << "\n"; EXV_WARNING << Error(30) << "\n";
#endif #endif
} }
return rc; return rc;

@ -449,7 +449,7 @@ namespace Exiv2 {
if (!initialize()) { if (!initialize()) {
#ifndef SUPPRESS_WARNINGS #ifndef SUPPRESS_WARNINGS
std::cerr << "XMP Toolkit initialization failed.\n"; EXV_ERROR << "XMP toolkit initialization failed.\n";
#endif #endif
return 2; return 2;
} }
@ -568,7 +568,7 @@ namespace Exiv2 {
} }
#ifndef SUPPRESS_WARNINGS #ifndef SUPPRESS_WARNINGS
catch (const XMP_Error& e) { catch (const XMP_Error& e) {
std::cerr << Error(40, e.GetID(), e.GetErrMsg()) << "\n"; EXV_ERROR << Error(40, e.GetID(), e.GetErrMsg()) << "\n";
xmpData.clear(); xmpData.clear();
return 3; return 3;
} }
@ -586,7 +586,7 @@ namespace Exiv2 {
xmpData.clear(); xmpData.clear();
if (!xmpPacket.empty()) { if (!xmpPacket.empty()) {
#ifndef SUPPRESS_WARNINGS #ifndef SUPPRESS_WARNINGS
std::cerr << "Warning: XMP toolkit support not compiled in.\n"; EXV_WARNING << "XMP toolkit support not compiled in.\n";
#endif #endif
} }
return 1; return 1;
@ -606,7 +606,7 @@ namespace Exiv2 {
if (!initialize()) { if (!initialize()) {
#ifndef SUPPRESS_WARNINGS #ifndef SUPPRESS_WARNINGS
std::cerr << "XMP Toolkit initialization failed.\n"; EXV_ERROR << "XMP toolkit initialization failed.\n";
#endif #endif
return 2; return 2;
} }
@ -689,7 +689,7 @@ namespace Exiv2 {
} }
#ifndef SUPPRESS_WARNINGS #ifndef SUPPRESS_WARNINGS
catch (const XMP_Error& e) { catch (const XMP_Error& e) {
std::cerr << Error(40, e.GetID(), e.GetErrMsg()) << "\n"; EXV_ERROR << Error(40, e.GetID(), e.GetErrMsg()) << "\n";
return 3; return 3;
} }
#else #else
@ -706,7 +706,7 @@ namespace Exiv2 {
{ {
if (!xmpData.empty()) { if (!xmpData.empty()) {
#ifndef SUPPRESS_WARNINGS #ifndef SUPPRESS_WARNINGS
std::cerr << "Warning: XMP toolkit support not compiled in.\n"; EXV_WARNING << "XMP toolkit support not compiled in.\n";
#endif #endif
} }
return 1; return 1;

@ -106,7 +106,7 @@ namespace Exiv2 {
xmpPacket_ = xmpPacket; xmpPacket_ = xmpPacket;
if (xmpPacket_.size() > 0 && XmpParser::decode(xmpData_, xmpPacket_)) { if (xmpPacket_.size() > 0 && XmpParser::decode(xmpData_, xmpPacket_)) {
#ifndef SUPPRESS_WARNINGS #ifndef SUPPRESS_WARNINGS
std::cerr << "Warning: Failed to decode XMP metadata.\n"; EXV_WARNING << "Failed to decode XMP metadata.\n";
#endif #endif
} }
copyXmpToIptc(xmpData_, iptcData_); copyXmpToIptc(xmpData_, iptcData_);
@ -126,7 +126,7 @@ namespace Exiv2 {
if (XmpParser::encode(xmpPacket_, xmpData_, if (XmpParser::encode(xmpPacket_, xmpData_,
XmpParser::omitPacketWrapper|XmpParser::useCompactFormat) > 1) { XmpParser::omitPacketWrapper|XmpParser::useCompactFormat) > 1) {
#ifndef SUPPRESS_WARNINGS #ifndef SUPPRESS_WARNINGS
std::cerr << "Error: Failed to encode XMP metadata.\n"; EXV_ERROR << "Failed to encode XMP metadata.\n";
#endif #endif
} }
} }

Loading…
Cancel
Save