コード例 #1
0
bool StringHelper::equalsIgnoreCase(const LogString& s1, const LogString& upper, const LogString& lower) {
  LogString::const_iterator u = upper.begin();
  LogString::const_iterator l = lower.begin();
  LogString::const_iterator iter = s1.begin();
  for (;
       iter != s1.end() && u != upper.end() && l != lower.end();
       iter++, u++, l++) {
       if (*iter != *u && *iter != *l) return false;
  }
  return u == upper.end() && iter == s1.end();
}
コード例 #2
0
LogString StringHelper::toLowerCase(const LogString& s)
{
        LogString d;
        std::transform(s.begin(), s.end(),
                std::insert_iterator<LogString>(d, d.begin()), tolower);
        return d;
}
コード例 #3
0
bool StringHelper::equalsIgnoreCase(const LogString& s1, const logchar* upper, const logchar* lower) {
  for (LogString::const_iterator iter = s1.begin();
       iter != s1.end();
       iter++, upper++, lower++) {
       if (*iter != *upper && *iter != * lower) return false;
  }
  return (*upper == 0);
}
コード例 #4
0
 void testDecodeUTF8_4() {
     std::string src("\xC2\xA9");
     LogString out;
     Transcoder::decodeUTF8(src, out);
     LogString::const_iterator iter = out.begin();
     unsigned int sv = Transcoder::decode(out, iter);
     LOGUNIT_ASSERT_EQUAL((unsigned int) 0xA9, sv);
     LOGUNIT_ASSERT_EQUAL(true, iter == out.end());
 }
コード例 #5
0
void OutputStreamWriter::write(const LogString& str, Pool& p) {
  if (str.length() > 0) {
    enum { BUFSIZE = 1024 };
    char rawbuf[BUFSIZE];
    ByteBuffer buf(rawbuf, (size_t) BUFSIZE);
    enc->reset();
    LogString::const_iterator iter = str.begin();
    while(iter != str.end()) {
      CharsetEncoder::encode(enc, str, iter, buf);
      buf.flip();
      out->write(buf, p);
      buf.clear();
    }
    CharsetEncoder::encode(enc, str, iter, buf);
    enc->flush(buf);
    buf.flip();
    out->write(buf, p);
  }
}
コード例 #6
0
LogString OptionConverter::convertSpecialChars(const LogString& s)
{
    logchar c;
    LogString sbuf;

    LogString::const_iterator i = s.begin();
    while(i != s.end())
        {
                c = *i++;
                if (c == 0x5C /* '\\' */)
                {
                        c =  *i++;

                        switch (c)
                        {
                        case 0x6E: //'n'
                                c = 0x0A;
                                break;

                        case 0x72: //'r'
                                c = 0x0D;
                                break;

                        case 0x74: //'t'
                                c = 0x09;
                                break;

                        case 0x66: //'f'
                                c = 0x0C;
                                break;
                        default:
                                break;
                        }
                }
                sbuf.append(1, c);
    }
    return sbuf;
}
コード例 #7
0
/**
 * Purge and rename old log files in preparation for rollover
 * @param lowIndex low index
 * @param highIndex high index.  Log file associated with high
 * index will be deleted if needed.
 * @return true if purge was successful and rollover should be attempted.
 */
bool FixedWindowRollingPolicy::purge(int lowIndex, int highIndex, Pool& p) const {
  int suffixLength = 0;

  std::vector<FileRenameActionPtr> renames;
  LogString buf;
  ObjectPtr obj = new Integer(lowIndex);
  formatFileName(obj, buf, p);

  LogString lowFilename(buf);

  if (lowFilename.compare(lowFilename.length() - 3, 3, LOG4CXX_STR(".gz")) == 0) {
    suffixLength = 3;
  } else if (lowFilename.compare(lowFilename.length() - 4, 4, LOG4CXX_STR(".zip")) == 0) {
    suffixLength = 4;
  }

  for (int i = lowIndex; i <= highIndex; i++) {
    File toRenameCompressed;
    toRenameCompressed.setPath(lowFilename);
    File toRenameBase;
    toRenameBase.setPath(lowFilename.substr(0, lowFilename.length() - suffixLength));
    File* toRename = &toRenameCompressed;
    bool isBase = false;
    bool exists = toRenameCompressed.exists(p);

    if (suffixLength > 0) {
      if (exists) {
        if (toRenameBase.exists(p)) {
          toRenameBase.deleteFile(p);
        }
      } else {
        toRename = &toRenameBase;
        exists = toRenameBase.exists(p);
        isBase = true;
      }
    }

    if (exists) {
      //
      //    if at upper index then
      //        attempt to delete last file
      //        if that fails then abandon purge
      if (i == highIndex) {
        if (!toRename->deleteFile(p)) {
          return false;
        }

        break;
      }

      //
      //   if intermediate index
      //     add a rename action to the list
      buf.erase(buf.begin(), buf.end());
      obj = new Integer(i + 1);
      formatFileName(obj, buf, p);

      LogString highFilename(buf);
      LogString renameTo(highFilename);

      if (isBase) {
        renameTo =
          highFilename.substr(0, highFilename.length() - suffixLength);
      }

      renames.push_back(new FileRenameAction(*toRename, File().setPath(renameTo), true));
      lowFilename = highFilename;
    } else {
      break;
    }
  }

  //
  //   work renames backwards
  //
  for(std::vector<FileRenameActionPtr>::reverse_iterator iter = renames.rbegin();
      iter != renames.rend();
      iter++) {

     try {
         if (!(*iter)->execute(p)) {
            return false;
         }
     } catch (std::exception& ) {
        LogLog::warn(LOG4CXX_STR("Exception during purge in RollingFileAppender"));

        return false;
     }
  }
  return true;
}