Re: [Log4cplus-devel] compatibility question concerning log4cplus::tstring
Logging Framework for C++
Brought to you by:
wilx
From: Václav Z. <vha...@gm...> - 2012-08-02 10:03:25
|
On 2 August 2012 11:00, Václav Zeman wrote: > On 1 August 2012 17:13, John Lumby wrote: >> Hello, I'd like to ask about compatibility of log4cplus::tstring between 1.0.x and 1.1.x > As I have written in reply in another thread, my intention has always > been to keep log4cplus source compatible between versions. > >> >> An application (bind10) has some code like so: >> >> // Convert logging level to string. If the level is a valid debug level, >> // return the string DEBUG, else return the empty string. >> log4cplus::tstring >> LoggerLevelImpl::logLevelToString(log4cplus::LogLevel level) { >> Level bindlevel = convertToBindLevel(level); >> Severity& severity = bindlevel.severity; >> int& dbglevel = bindlevel.dbglevel; >> >> if ((severity == DEBUG) && >> ((dbglevel >= MIN_DEBUG_LEVEL) && (dbglevel <= MAX_DEBUG_LEVEL))) { >> return (tstring("DEBUG")); >> } >> >> // Unknown, so return empty string for log4cplus to try other conversion >> // functions. >> return (tstring()); >> } >> >> // Initialization. Register the conversion functions with the LogLevelManager. >> void >> LoggerLevelImpl::init() { >> >> // Get the singleton log-level manager. >> LogLevelManager& manager = getLogLevelManager(); >> >> // Register the conversion functions >> manager.pushFromStringMethod(LoggerLevelImpl::logLevelFromString); >> manager.pushToStringMethod(LoggerLevelImpl::logLevelToString); >> } >> >> which compiles correctly against 1.0.x >> >> But compiling against 1.1.x results in >> >> logger_level_impl.cc:189:1: error: prototype for >> ‘const tstring& isc::log::LoggerLevelImpl::logLevelToString(log4cplus::LogLevel)’ >> does not match any in class ‘isc::log::LoggerLevelImpl’ >> ../../../src/lib/log/logger_level_impl.h:115:31: error: >> candidate is: static log4cplus::tstring isc::log::LoggerLevelImpl::logLevelToString(log4cplus::LogLevel) >> In static member function ‘static void isc::log::LoggerLevelImpl::init()’: >> >> Changing the application code to read as follows fixes the problem ... >> >> // Convert logging level to string. If the level is a valid debug level, >> // return the string DEBUG, else return the empty string. >> log4cplus::tstring const & >> LoggerLevelImpl::logLevelToString(log4cplus::LogLevel level) { >> >> static const tstring debug_string("DEBUG"); >> static const tstring empty_string; >> >> Level bindlevel = convertToBindLevel(level); >> Severity& severity = bindlevel.severity; >> int& dbglevel = bindlevel.dbglevel; >> >> if ((severity == DEBUG) && >> ((dbglevel >= MIN_DEBUG_LEVEL) && (dbglevel <= MAX_DEBUG_LEVEL))) { >> return (debug_string); >> } >> >> // Unknown, so return empty string for log4cplus to try other conversion >> // functions. >> return (empty_string); >> } >> >> but creates two new problems: >> . code is less general - every possible string value which might be returned must be explicitly declared >> (fortunately there are only two - "DEBUG" and "") > I do not regard this as a problem. The set of log levels is intended > to be small. The change of return type to reference to tstring is > there for speed. > >> . code no longer compiles against 1.0.x - > This is a problem. What you have discovered breaks the source > compatibility intention and I am going to fix it by allowing both old > and new callbacks. > >> logger_level_impl.cc: In static member function 'static void >> isc::log::LoggerLevelImpl::init()': >> logger_level_impl.cc:217: error: invalid conversion from 'const >> log4cplus::tstring& (*)(log4cplus::LogLevel)' to 'log4cplus::tstring >> (*)(log4cplus::LogLevel)' >> logger_level_impl.cc:217: error: initializing argument 1 of 'void >> log4cplus::LogLevelManager::pushToStringMethod(log4cplus::tstring >> (*)(log4cplus::LogLevel))' >> >> Has anyone else run into this? >> And is it possible to write the application code for registering and running the logLevelToString() method in such a way that it >> compiles correctly against both log4cplus releases? I am attaching a patch that should allow using callbacks with both return types. If there is any other source incompatibility, please let me know. -- VZ |