Changeset 141 in pacpusframework


Ignore:
Timestamp:
07/30/13 17:48:06 (11 years ago)
Author:
Marek Kurdej
Message:

Major update: using Boost.Log if PACPUS_USE_LOG is true.
Added: overloaded operator<< for QString (explicit instantiation).

Location:
branches/2.0-beta1
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • branches/2.0-beta1/cmake/PacpusDependencies.cmake

    r130 r141  
    9191# Do not use compiled modules, include-only headers.
    9292# ========================================
    93 #find_package(Boost 1.49.0 REQUIRED)
    94 #list(APPEND PACPUS_DEPENDENCIES_INC ${Boost_INCLUDE_DIRS})
    95 
    96 # ========================================
    97 # log4cxx
    98 # ========================================
    9993if(PACPUS_USE_LOG)
    100     if(WIN32 AND MSVC AND IS_BUILDING_PACPUS)
    101         set(LOG4CXX_ROOT ${PACPUS_3RD_PARTY_DIR}/apache-log4cxx)
    102     endif()
    103 
    104     find_package(log4cxx REQUIRED)
    105 
    10694    list(APPEND PACPUS_DEFINITIONS " -DPACPUS_USE_LOG ")
    107     list(APPEND PACPUS_DEPENDENCIES_INC ${LOG4CXX_INCLUDE_DIRS})
    108     list(APPEND PACPUS_DEPENDENCIES_LIB ${LOG4CXX_LIBRARIES})
    109 
    110     # If needed, install the dll of log4cxx
    111     if(WIN32 AND MSVC AND IS_BUILDING_PACPUS)
    112         pacpus_get_msvc(MSVC_VERSION)
    113         pacpus_purge_backslash(LOG4CXX_ROOT)
    114 
    115         install(
    116             FILES
    117                 ${LOG4CXX_ROOT}/bin/${MSVC_VERSION}/log4cxx.dll
    118                 ${LOG4CXX_ROOT}/bin/${MSVC_VERSION}/log4cxx_d.dll
    119             DESTINATION
    120                 ${PACPUS_INSTALL_DIR}/bin
    121         )
    122     endif()
     95    list(APPEND PACPUS_DEFINITIONS " -DBOOST_ALL_DYN_LINK ")
     96   
     97    find_package(Boost 1.54.0 REQUIRED
     98        COMPONENTS
     99            log
     100    )
     101    include_directories(${Boost_INCLUDE_DIRS})
     102    link_directories(${Boost_LIBRARY_DIRS})
     103   
     104    list(APPEND PACPUS_DEPENDENCIES_INC ${Boost_INCLUDE_DIRS})
     105    list(APPEND PACPUS_DEPENDENCIES_LIB ${Boost_LIBRARIES})
    123106endif()
    124107
  • branches/2.0-beta1/include/Pacpus/kernel/DbiteException.h

    r89 r141  
    4343    virtual const char* what() const throw();
    4444
    45 
    4645private:
    4746    std::string mWhat;
  • branches/2.0-beta1/include/Pacpus/kernel/Log.h

    r89 r141  
    2828public:
    2929    LogConfigurator();
    30     ~LogConfigurator();
    31 
    3230    static void configureLoggerWithFile(const char * configFilename);
    33 } initializer; // using Schwarz/nifty counter idiom for static initialization
     31} logInitializer;
    3432
    3533} // namespace pacpus
    3634
    37 #ifdef PACPUS_USE_LOG
    38   #include <log4cxx/logger.h>
     35#if defined(PACPUS_USE_LOG)
    3936
    40   class QString;
    41  
    42   #define DECLARE_STATIC_LOGGER(name) \
    43     static log4cxx::LoggerPtr logger(log4cxx::Logger::getLogger(name))
     37#include <boost/log/trivial.hpp>
     38#include <iosfwd>
     39class QString;
    4440
    45   #define LOG_TRACE(message)          LOG4CXX_TRACE(logger, message)
    46   #define LOG_DEBUG(message)          LOG4CXX_DEBUG(logger, message)
    47   #define LOG_INFO(message)           LOG4CXX_INFO(logger, message)
    48   #define LOG_WARN(message)           LOG4CXX_WARN(logger, message)
    49   #define LOG_ERROR(message)          LOG4CXX_ERROR(logger, message)
    50   #define LOG_FATAL(message)          LOG4CXX_FATAL(logger, message)
     41template< typename CharT, typename TraitsT >
     42PACPUSLIB_API std::basic_ostream< CharT, TraitsT >& operator<< (std::basic_ostream< CharT, TraitsT >& strm, QString const& s);
    5143
    52   /// Output stream ::log4cxx::helpers::CharMessageBuffer operator for QString
    53   PACPUSLIB_API ::log4cxx::helpers::CharMessageBuffer & operator<<(::log4cxx::helpers::CharMessageBuffer & os, const QString & s);
    54   /// Output stream ::log4cxx::helpers::MessageBuffer operator for QString
    55   PACPUSLIB_API ::log4cxx::helpers::CharMessageBuffer & operator<<(::log4cxx::helpers::MessageBuffer & os, const QString & s);
     44#define DECLARE_STATIC_LOGGER(name)
     45
     46#define LOG(level, message)         BOOST_LOG_TRIVIAL(level) << message
     47#define LOG_TRACE(message)          LOG(trace, message)
     48#define LOG_DEBUG(message)          LOG(debug, message)
     49#define LOG_INFO(message)           LOG(info, message)
     50#define LOG_WARN(message)           LOG(warning, message)
     51#define LOG_ERROR(message)          LOG(error, message)
     52#define LOG_FATAL(message)          LOG(fatal, message)
    5653
    5754#else
    58   /// Declares a log4cxx logger
    59   ///
    60   /// @param name Name of the logger, displayed when logging a message.
    61   #define DECLARE_STATIC_LOGGER(name)
    62   /// Logs a message at TRACE level using default logger
    63   #define LOG_TRACE(message)
    64   /// Logs a message at DEBUG level using default logger
    65   #define LOG_DEBUG(message)
    66   /// Logs a message at INFO level using default logger
    67   #define LOG_INFO(message)
    68   /// Logs a message at WARN level using default logger
    69   #define LOG_WARN(message)
    70   /// Logs a message at ERROR level using default logger
    71   #define LOG_ERROR(message)
    72   /// Logs a message at FATAL level using default logger
    73   #define LOG_FATAL(message)
     55
     56/// @param name Name of the logger, displayed when logging a message.
     57#define DECLARE_STATIC_LOGGER(name)
     58/// Logs a message at TRACE level using default logger
     59#define LOG_TRACE(message)
     60/// Logs a message at DEBUG level using default logger
     61#define LOG_DEBUG(message)
     62/// Logs a message at INFO level using default logger
     63#define LOG_INFO(message)
     64/// Logs a message at WARN level using default logger
     65#define LOG_WARN(message)
     66/// Logs a message at ERROR level using default logger
     67#define LOG_ERROR(message)
     68/// Logs a message at FATAL level using default logger
     69#define LOG_FATAL(message)
     70
    7471#endif // PACPUS_USE_LOG
    7572
  • branches/2.0-beta1/include/Pacpus/kernel/PacpusApplication.h

    r89 r141  
    1616
    1717#include <QApplication>
     18
     19#include <Pacpus/kernel/pacpus.h>
    1820
    1921namespace pacpus {
  • branches/2.0-beta1/src/DBITEPlayerLib/DbtPlyFileManager.cpp

    r89 r141  
    120120            dbt.pfile->open(mDbtFilenameList.at(i).toStdString(), ReadMode);
    121121        } catch (DbiteException & e) {
     122            (void) e; // unused
    122123            LOG_ERROR("cannot open DBT file \"" << mDbtFilenameList.at(i) << "\"");
    123124            LOG_DEBUG("error: " << e.what());
     
    179180void DbtPlyFileManager::displayUI()
    180181{
    181     //LOG_WARN("component '" << componentName << "' has no user interface. Please set ui property to 0 in your XML configuration");
     182    LOG_WARN("component '" << componentName << "' has no user interface. Please set ui property to 0 in your XML configuration");
    182183}
    183184
  • branches/2.0-beta1/src/FileLib/src/DbiteFile.cpp

    r89 r141  
    9595        checkFileOpen();
    9696    } catch (DbiteException & e) {
     97        (void) e; // unused
    9798        LOG_ERROR("Dbite exception: " << e.what());
    9899        close();
     
    103104        readHeader();
    104105    } catch (DbiteException & e) {
     106        (void) e; // unused
    105107        LOG_ERROR("Dbite exception: " << e.what());
    106108        // TODO: readAndDiagnoseHeader();
     
    164166            // TODO: check if same type and record size
    165167        } catch (DbiteException & e) {
     168            (void) e; // unused
    166169            LOG_ERROR("Dbite exception: " << e.what());
    167170            // TODO: readAndDiagnoseHeader();
     
    208211            writeHeader();
    209212        } catch (DbiteException & e) {
     213            (void) e; // unused
    210214            LOG_ERROR("cannot write header on close: " << e.what());
    211215        }
  • branches/2.0-beta1/src/PacpusLib/ComponentManager.cpp

    r120 r141  
    343343
    344344    LOG_INFO("starting component '" << componentName << "'...");
    345     if (!component->startComponent())
     345    if (!component->startComponent()) {
    346346        LOG_WARN("cannot start component '" << componentName << "'. It can already be started");
     347    }
    347348
    348349    return true;
     
    372373
    373374    LOG_INFO("stopping component '" << componentName << "'...");
    374     if (!component->stopComponent())
     375    if (!component->stopComponent()) {
    375376        LOG_WARN("cannot stop component '" << componentName << "'" << ". It can be already stopped");
     377    }
    376378
    377379    return true;
     
    383385
    384386    ComponentMap::iterator it = componentMap_.find(name);
    385     if (it != componentMap_.end())
     387    if (it != componentMap_.end()) {
    386388        return *it;
     389    }
    387390
    388391    LOG_WARN("cannot retrieve component '" << name << "'" << ". It does not exist");
  • branches/2.0-beta1/src/PacpusLib/Log.cpp

    r89 r141  
    99#ifdef PACPUS_USE_LOG
    1010
    11 #ifdef _MSC_VER
    12 #   pragma warning(push)
    13 #   pragma warning(disable: 4231 4251)
    14 #endif // _MSC_VER
    15 
    16 #include <log4cxx/basicconfigurator.h>
    17 #include <log4cxx/consoleappender.h>
    18 #include <log4cxx/patternlayout.h>
    19 #include <log4cxx/propertyconfigurator.h>
     11#include <ostream>
    2012#include <QString>
    2113
    22 #ifdef _MSC_VER
    23 #   pragma warning(pop)
    24 #endif // _MSC_VER
     14template< typename CharT, typename TraitsT >
     15std::basic_ostream< CharT, TraitsT >& operator<< (std::basic_ostream< CharT, TraitsT >& strm, QString const& s)
     16{
     17    strm << s.toStdString();
     18    return strm;
     19}
    2520
    26 using namespace log4cxx;
     21// explicit instantiation
     22template
     23PACPUSLIB_API std::basic_ostream<char>& operator<< (std::basic_ostream<char>& strm, QString const& s);
     24
     25#endif // PACPUS_USE_LOG
    2726
    2827namespace pacpus {
     28   
     29#if defined(PACPUS_USE_LOG)
    2930
    30 static int niftyCounter;
     31//#include <boost/log/utility/setup/formatter_parser.hpp>
     32
     33//void init_log_factories()
     34//{
     35//    //boost::log::register_simple_formatter_factory< QString, char >("QString");
     36//}
     37
     38#endif // PACPUS_USE_LOG
    3139
    3240LogConfigurator::LogConfigurator()
    3341{
    34     using namespace log4cxx;
    35 
    36     if (0 == niftyCounter++) {
    37         BasicConfigurator::resetConfiguration();
    38 
    39         LayoutPtr lp(new PatternLayout(LOG4CXX_STR("%-6r [%-5p] %30.30c - %m%n")));
    40         AppenderPtr ap(new ConsoleAppender(lp));
    41         BasicConfigurator::configure(ap);
    42         Logger::getRootLogger()->setLevel(log4cxx::Level::getInfo());
    43     }
    44 }
    45 
    46 LogConfigurator::~LogConfigurator()
    47 {
    48     if (0 == --niftyCounter) {
    49         // clean up
    50     }
    51 }
    52 
    53 void LogConfigurator::configureLoggerWithFile(const char * configFilename)
    54 {
    55     BasicConfigurator::resetConfiguration();
    56     PropertyConfigurator::configure(configFilename);
    57 }
    58 
    59 } // namespace pacpus
    60 
    61 helpers::CharMessageBuffer & operator<<(helpers::CharMessageBuffer & os, const QString & val)
    62 {
    63     return os << val.toStdString();
    64 }
    65 
    66 helpers::CharMessageBuffer & operator<<(helpers::MessageBuffer & os, const QString & val)
    67 {
    68     return os << val.toStdString();
    69 }
    70 
    71 #else // PACPUS_USE_LOG
    72 
    73 namespace pacpus {
    74 
    75 LogConfigurator::LogConfigurator()
    76 {
    77 }
    78 
    79 LogConfigurator::~LogConfigurator()
    80 {
     42#if defined(PACPUS_USE_LOG)
     43    //init_log_factories();
     44#endif // PACPUS_USE_LOG
    8145}
    8246
     
    8650
    8751} // namespace pacpus
    88 
    89 #endif // PACPUS_USE_LOG
  • branches/2.0-beta1/src/PacpusLib/PacpusApplication.cpp

    r89 r141  
    8484        return QApplication::notify(receiver, ev);
    8585    } catch(DbiteException & e) {
     86        (void) e; // unused
    8687        LOG_ERROR("DbiteException thrown:" << e.what());
    8788    } catch(std::exception & e) {
     89        (void) e; // unused
    8890        LOG_ERROR("std::exception thrown:" << e.what());
    8991    }
Note: See TracChangeset for help on using the changeset viewer.