Hi,
attached is the patch to format the {n} placeholders in l7d texts.
It builds upon the patch I sent two days ago. With these two patches,
the L7dTestCase completes successfully.
Best Regards,
Andreas
--
Andreas Fester
mailto:[EMAIL PROTECTED]
WWW: http://www.littletux.net
ICQ: 326674288
diff -urN log4cxx-0.9.8.org/include/log4cxx/helpers/stringhelper.h log4cxx-0.9.8/include/log4cxx/helpers/stringhelper.h
--- log4cxx-0.9.8.org/include/log4cxx/helpers/stringhelper.h 2005-05-04 18:13:40.000000000 +0200
+++ log4cxx-0.9.8/include/log4cxx/helpers/stringhelper.h 2005-09-29 21:57:03.000000000 +0200
@@ -18,7 +18,7 @@
#define _LOG4CXX_HELPERS_STRING_HELPER_H
#include <log4cxx/logstring.h>
-#include <stdarg.h>
+#include <vector>
namespace log4cxx
@@ -59,6 +59,8 @@
static bool getline(std::string& buf, std::string& line);
+ static LogString format(const LogString& pattern, const std::vector<LogString>& params);
+
#if LOG4CXX_HAS_WCHAR_T
static std::wstring trim(const std::wstring& s);
static bool startsWith(const std::wstring& s, const std::wstring& suffix);
diff -urN log4cxx-0.9.8.org/include/log4cxx/logger.h log4cxx-0.9.8/include/log4cxx/logger.h
--- log4cxx-0.9.8.org/include/log4cxx/logger.h 2005-05-04 18:13:40.000000000 +0200
+++ log4cxx-0.9.8/include/log4cxx/logger.h 2005-09-29 21:17:06.000000000 +0200
@@ -452,23 +452,44 @@
First, the user supplied
<code>key</code> is searched in the resource bundle. Next, the resulting
pattern is formatted using helpers::StringHelper::format method with the user
- supplied object array <code>params</code>.
+ supplied string array <code>params</code>.
@param level The level of the logging request.
- @param key The key to be searched in the #resourceBundle.
- @param file The source file of the logging request, may be null.
- @param line The number line of the logging request.
+ @param key The key to be searched in the #ResourceBundle.
+ @param locationInfo The location info of the logging request.
+ @param values The values for the placeholders <code>{0}</code>,
+ <code>{1}</code> etc. within the pattern.
@see #setResourceBundle
*/
+ void l7dlog(const LevelPtr& level, const LogString& key,
+ const log4cxx::spi::LocationInfo& locationInfo,
+ const std::vector<LogString>& values);
+
#if LOG4CXX_HAS_WCHAR_T
void l7dlog(const LevelPtr& level, const std::wstring& key,
- const log4cxx::spi::LocationInfo& locationInfo,
- ...);
+ const log4cxx::spi::LocationInfo& locationInfo);
+ void l7dlog(const LevelPtr& level, const std::wstring& key,
+ const log4cxx::spi::LocationInfo& locationInfo,
+ const std::wstring& val1);
+ void l7dlog(const LevelPtr& level, const std::wstring& key,
+ const log4cxx::spi::LocationInfo& locationInfo,
+ const std::wstring& val1, const std::wstring& val2);
+ void l7dlog(const LevelPtr& level, const std::wstring& key,
+ const log4cxx::spi::LocationInfo& locationInfo,
+ const std::wstring& val1, const std::wstring& val2, const std::wstring& val3);
#endif
void l7dlog(const LevelPtr& level, const std::string& key,
- const log4cxx::spi::LocationInfo& locationInfo,
- ...);
+ const log4cxx::spi::LocationInfo& locationInfo);
+ void l7dlog(const LevelPtr& level, const std::string& key,
+ const log4cxx::spi::LocationInfo& locationInfo,
+ const std::string& val1);
+ void l7dlog(const LevelPtr& level, const std::string& key,
+ const log4cxx::spi::LocationInfo& locationInfo,
+ const std::string& val1, const std::string& val2);
+ void l7dlog(const LevelPtr& level, const std::string& key,
+ const log4cxx::spi::LocationInfo& locationInfo,
+ const std::string& val1, const std::string& val2, const std::string& val3);
/**
This is the most generic printing method. It is intended to be
diff -urN log4cxx-0.9.8.org/src/logger.cpp log4cxx-0.9.8/src/logger.cpp
--- log4cxx-0.9.8.org/src/logger.cpp 2005-09-28 03:05:12.000000000 +0200
+++ log4cxx-0.9.8/src/logger.cpp 2005-09-29 22:07:00.000000000 +0200
@@ -25,7 +25,6 @@
#include <log4cxx/helpers/stringhelper.h>
#include <log4cxx/helpers/synchronized.h>
#include <log4cxx/helpers/transcoder.h>
-#include <stdarg.h>
#include <log4cxx/helpers/appenderattachableimpl.h>
#include <log4cxx/helpers/exception.h>
#include <log4cxx/helpers/aprinitializer.h>
@@ -343,8 +342,9 @@
}
}*/
-void Logger::l7dlog(const LevelPtr& level, const std::string& key,
- const LocationInfo& location, ...)
+
+void Logger::l7dlog(const LevelPtr& level, const LogString& key,
+ const LocationInfo& location, const std::vector<LogString>& params)
{
if (repository->isDisabled(level->toInt()))
{
@@ -353,66 +353,128 @@
if (level->isGreaterOrEqual(getEffectiveLevel()))
{
- LogString lkey;
- Transcoder::decode(key.c_str(), strlen(key.c_str()), lkey);
-
- LogString pattern = getResourceBundleString(lkey);
+ LogString pattern = getResourceBundleString(key);
LogString msg;
if (pattern.empty())
{
- msg = lkey;
+ msg = key;
}
else
{
- msg = pattern;
-#if 0
-// TODO
- va_list params;
- va_start (params, line);
msg = StringHelper::format(pattern, params);
- va_end (params);
-#endif
}
forcedLog(level, msg, location);
}
}
+void Logger::l7dlog(const LevelPtr& level, const std::string& key,
+ const LocationInfo& location) {
+ LogString lkey;
+ Transcoder::decode(key.c_str(), strlen(key.c_str()), lkey);
+
+ std::vector<LogString> values(0);
+ l7dlog(level, lkey, location, values);
+}
+
+void Logger::l7dlog(const LevelPtr& level, const std::string& key,
+ const LocationInfo& location, const std::string& val1) {
+ LogString lval1;
+ Transcoder::decode(val1.c_str(), strlen(val1.c_str()), lval1);
+ LogString lkey;
+ Transcoder::decode(key.c_str(), strlen(key.c_str()), lkey);
+
+ std::vector<LogString> values(1);
+ values[0] = lval1;
+ l7dlog(level, lkey, location, values);
+}
+
+void Logger::l7dlog(const LevelPtr& level, const std::string& key,
+ const LocationInfo& location,
+ const std::string& val1, const std::string& val2) {
+ LogString lval1;
+ LogString lval2;
+ Transcoder::decode(val1.c_str(), strlen(val1.c_str()), lval1);
+ Transcoder::decode(val2.c_str(), strlen(val2.c_str()), lval2);
+ LogString lkey;
+ Transcoder::decode(key.c_str(), strlen(key.c_str()), lkey);
+
+ std::vector<LogString> values(2);
+ values[0] = lval1;
+ values[1] = lval2;
+ l7dlog(level, lkey, location, values);
+}
+
+void Logger::l7dlog(const LevelPtr& level, const std::string& key,
+ const LocationInfo& location,
+ const std::string& val1, const std::string& val2, const std::string& val3) {
+ LogString lval1;
+ LogString lval2;
+ LogString lval3;
+ Transcoder::decode(val1.c_str(), strlen(val1.c_str()), lval1);
+ Transcoder::decode(val2.c_str(), strlen(val2.c_str()), lval2);
+ Transcoder::decode(val3.c_str(), strlen(val3.c_str()), lval3);
+ LogString lkey;
+ Transcoder::decode(key.c_str(), strlen(key.c_str()), lkey);
+
+ std::vector<LogString> values(3);
+ values[0] = lval1;
+ values[1] = lval2;
+ values[3] = lval3;
+ l7dlog(level, lkey, location, values);
+}
+
+
#if LOG4CXX_HAS_WCHAR_T
+
void Logger::l7dlog(const LevelPtr& level, const std::wstring& key,
- const LocationInfo& location, ...)
-{
- if (repository->isDisabled(level->toInt()))
- {
- return;
- }
+ const LocationInfo& location) {
+ LOG4CXX_DECODE_WCHAR(lkey, key);
- if (level->isGreaterOrEqual(getEffectiveLevel()))
- {
- LOG4CXX_DECODE_WCHAR(lkey, key);
- LogString pattern = getResourceBundleString(lkey);
- LogString msg;
+ std::vector<LogString> values(0);
+ l7dlog(level, lkey, location, values);
+}
- if (pattern.empty())
- {
- msg = lkey;
- }
- else
- {
- msg = pattern;
-#if 0
-// TODO
- va_list params;
- va_start (params, line);
- msg = StringHelper::format(pattern, params);
- va_end (params);
-#endif
- }
+void Logger::l7dlog(const LevelPtr& level, const std::wstring& key,
+ const LocationInfo& location,
+ const std::wstring& val1) {
+ LOG4CXX_DECODE_WCHAR(lval1, val1);
+ LOG4CXX_DECODE_WCHAR(lkey, key);
+
+ std::vector<LogString> values(1);
+ values[0] = lval1;
+ l7dlog(level, key, location, values);
+}
- forcedLog(level, msg, location);
- }
+void Logger::l7dlog(const LevelPtr& level, const std::wstring& key,
+ const LocationInfo& location,
+ const std::wstring& val1, const std::wstring& val2) {
+ LOG4CXX_DECODE_WCHAR(lval1, val1);
+ LOG4CXX_DECODE_WCHAR(lval2, val2);
+ LOG4CXX_DECODE_WCHAR(lkey, key);
+
+ std::vector<LogString> values(2);
+ values[0] = lval1;
+ values[1] = lval2;
+ l7dlog(level, key, location, values);
}
+
+void Logger::l7dlog(const LevelPtr& level, const std::wstring& key,
+ const LocationInfo& location,
+ const std::wstring& val1, const std::wstring& val2, const std::wstring& val3) {
+ LOG4CXX_DECODE_WCHAR(lval1, val1);
+ LOG4CXX_DECODE_WCHAR(lval2, val2);
+ LOG4CXX_DECODE_WCHAR(lval3, val3);
+ LOG4CXX_DECODE_WCHAR(lkey, key);
+
+ std::vector<LogString> values(3);
+ values[0] = lval1;
+ values[1] = lval2;
+ values[2] = lval3;
+ l7dlog(level, key, location, values);
+}
+
#endif
void Logger::removeAllAppenders()
diff -urN log4cxx-0.9.8.org/src/stringhelper.cpp log4cxx-0.9.8/src/stringhelper.cpp
--- log4cxx-0.9.8.org/src/stringhelper.cpp 2005-05-07 17:12:15.000000000 +0200
+++ log4cxx-0.9.8/src/stringhelper.cpp 2005-09-29 22:00:10.000000000 +0200
@@ -294,3 +294,23 @@
}
return s;
}
+
+
+LogString StringHelper::format(const LogString& pattern, const std::vector<LogString>& params) {
+
+ LogString result;
+ int i = 0;
+ while(pattern[i] != LOG4CXX_STR('\0')) {
+ if (pattern[i] == LOG4CXX_STR('{') && pattern[i + 1] >= LOG4CXX_STR('0') &&
+ pattern[i + 1] <= LOG4CXX_STR('9') && pattern[i + 2] == LOG4CXX_STR('}')) {
+ int arg = pattern[i + 1] - LOG4CXX_STR('0');
+ result = result + params[arg];
+ i += 3;
+ } else {
+ result = result + pattern[i];
+ i++;
+ }
+ }
+
+ return result;
+}