Uploaded image for project: 'Log4cxx'
  1. Log4cxx
  2. LOGCXX-84

Problems with stream logging in UTF8, no WCHAR_T build

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • 0.10.0
    • 0.10.0
    • Build
    • None
    • Windows XP, Visual Studio 2005, CVS log4cxx build with UTF8

    Description

      log4cxx dll built with log4cxx.h set to:
      #define LOG4CXX_LOGCHAR_IS_UTF8 1
      #define LOG4CXX_HAS_WCHAR_T 0

      Build fails due to encode/decode missing. Changed unicodehelper.cpp+95 from:
      #if defined(_WIN32)
      unsigned int UnicodeHelper::decodeWide(const wchar_t*& src, const wchar_t* srcEnd) {

      to

      #if LOG4CXX_HAS_WCHAR_T && defined(_WIN32)
      unsigned int UnicodeHelper::decodeWide(const wchar_t*& src, const wchar_t* srcEnd) {

      build worked, but when a client uses the library, it crashes when trying to destroy the string being streamed if not a std::string type (i.e. char). See 'logstr2 << "Testing stream" << LOG4CXX_ENDMSG' line in sample below.

      Note, this is with 'inline' added to stream.h

      Chris

      Sample code:

      #include "stdafx.h"
      #include "Windows.h"
      #include <conio.h>

      log4cxx::LoggerPtr logger;
      log4cxx::logstream* logstr;

      int _tmain(int argc, _TCHAR* argv[])
      {
      logger = log4cxx::Logger::getRootLogger();
      log4cxx::PropertyConfigurator::configureAndWatch(log4cxx::File("log.cfg"));

      log4cxx::logstream logstr2(logger, log4cxx::Level::getError());
      logstr = &logstr2;

      LOG4CXX_DEBUG(logger, "Starting tests");

      int count = 0;
      while (!_kbhit())

      { count++; LOG4CXX_INFO(logger, "info message"); LOG4CXX_DEBUG(logger, "debug message"); LOG4CXX_ERROR(logger, "error message"); LOG4CXX_FATAL(logger, "fatal message"); // this works std::string tmp = "Testing stream, count="; logstr2 << tmp << count << LOG4CXX_ENDMSG; (*logstr) << tmp << count << LOG4CXX_ENDMSG; // this works logstr2 << std::string("Testing stream") << LOG4CXX_ENDMSG; // this fails logstr2 << "Testing stream" << LOG4CXX_ENDMSG; Sleep(1000); // wait 1 second }

      LOG4CXX_DEBUG(logger, "Stopped tests");

      printf("Press Q and RETURN\n");
      scanf("%d");

      return 0;
      }

      Attachments

        Activity

          People

            carnold@apache.org Curt Arnold
            obe1line Chris Storah
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: