Changeset 141 in pacpusframework for branches/2.0-beta1/src/PacpusLib/Log.cpp


Ignore:
Timestamp:
Jul 30, 2013, 5:48:06 PM (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).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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
Note: See TracChangeset for help on using the changeset viewer.