Author: carnold
Date: Tue Nov 6 12:25:45 2007
New Revision: 592542
URL: http://svn.apache.org/viewvc?rev=592542&view=rev
Log:
LOGCXX-18: Rewrite MessageBuffer for VC6
Modified:
logging/log4cxx/trunk/src/main/cpp/logger.cpp
logging/log4cxx/trunk/src/main/cpp/messagebuffer.cpp
logging/log4cxx/trunk/src/main/include/log4cxx/helpers/messagebuffer.h
logging/log4cxx/trunk/src/main/include/log4cxx/logger.h
logging/log4cxx/trunk/src/test/cpp/asyncappendertestcase.cpp
logging/log4cxx/trunk/src/test/cpp/net/socketservertestcase.cpp
logging/log4cxx/trunk/src/test/cpp/shortsocketserver.cpp
logging/log4cxx/trunk/src/test/cpp/streamtestcase.cpp
logging/log4cxx/trunk/src/test/cpp/xml/xmllayouttestcase.cpp
Modified: logging/log4cxx/trunk/src/main/cpp/logger.cpp
URL:
http://svn.apache.org/viewvc/logging/log4cxx/trunk/src/main/cpp/logger.cpp?rev=592542&r1=592541&r2=592542&view=diff
==============================================================================
--- logging/log4cxx/trunk/src/main/cpp/logger.cpp (original)
+++ logging/log4cxx/trunk/src/main/cpp/logger.cpp Tue Nov 6 12:25:45 2007
@@ -145,6 +145,14 @@
}
#endif
+void Logger::forcedLogLS(const LevelPtr& level1, const LogString& message,
+ const LocationInfo& location)
+{
+ Pool p;
+ LoggingEventPtr event(new LoggingEvent(this, level1, message,
location));
+ callAppenders(event, p);
+}
+
bool Logger::getAdditivity() const
{
@@ -720,6 +728,13 @@
}
}
+void Logger::logLS(const LevelPtr& level1, const LogString& message,
+ const log4cxx::spi::LocationInfo& location) {
+ if (isEnabledFor(level1)) {
+ forcedLogLS(level1, message, location);
+ }
+}
+
#if LOG4CXX_HAS_WCHAR_T
void Logger::warn(const std::wstring& msg, const log4cxx::spi::LocationInfo&
location) {
if (isEnabledFor(log4cxx::Level::getWarn())) {
@@ -747,3 +762,4 @@
forcedLog(log4cxx::Level::getWarn(), msg);
}
}
+
Modified: logging/log4cxx/trunk/src/main/cpp/messagebuffer.cpp
URL:
http://svn.apache.org/viewvc/logging/log4cxx/trunk/src/main/cpp/messagebuffer.cpp?rev=592542&r1=592541&r2=592542&view=diff
==============================================================================
--- logging/log4cxx/trunk/src/main/cpp/messagebuffer.cpp (original)
+++ logging/log4cxx/trunk/src/main/cpp/messagebuffer.cpp Tue Nov 6 12:25:45
2007
@@ -15,151 +15,137 @@
* limitations under the License.
*/
-#include <log4cxx/helpers/messagebuffer.h>
+#include <log4cxx/helpers/messagebuffer.h>
+#include <log4cxx/helpers/transcoder.h>
-using namespace log4cxx::helpers;
-
-CharMessageBuffer::CharMessageBuffer() {
- stream = 0;
-}
-
-CharMessageBuffer::~CharMessageBuffer() {
- delete stream;
-}
-
-CharMessageBuffer& CharMessageBuffer::operator<<(const std::string& msg) {
- buf.append(msg);
- return *this;
-}
-
-CharMessageBuffer& CharMessageBuffer::operator<<(const char* msg) {
- if (0 == msg) {
- buf.append("null");
- } else {
- buf.append(msg);
- }
- return *this;
-}
-
-CharMessageBuffer& CharMessageBuffer::operator<<(const char msg) {
- buf.append(1, msg);
- return *this;
-}
-
-const std::string& CharMessageBuffer::str(const CharMessageBuffer&) const {
- return buf;
-}
-
-std::string CharMessageBuffer::str(const std::ostream&) const {
- return stream->str();
-}
-
-MessageBuffer::MessageBuffer()
+using namespace log4cxx::helpers;
+
+CharMessageBuffer::CharMessageBuffer() : stream(0) {}
+
+CharMessageBuffer::~CharMessageBuffer() {
+ delete stream;
+}
+
+CharMessageBuffer& CharMessageBuffer::operator<<(const
std::basic_string<char>& msg) {
+ if (stream == 0) {
+ buf.append(msg);
+ } else {
+ *stream << msg;
+ }
+ return *this;
+}
+
+CharMessageBuffer& CharMessageBuffer::operator<<(const char* msg) {
+ const char* actualMsg = msg;
+ if (actualMsg == 0) {
+ actualMsg = "null";
+ }
+ if (stream == 0) {
+ buf.append(actualMsg);
+ } else {
+ *stream << actualMsg;
+ }
+ return *this;
+}
+
+CharMessageBuffer& CharMessageBuffer::operator<<(const char msg) {
+ if (stream == 0) {
+ buf.append(1, msg);
+ } else {
+ buf.assign(1, msg);
+ *stream << buf;
+ }
+ return *this;
+}
+
+CharMessageBuffer::operator std::basic_ostream<char>&() {
+ if (stream == 0) {
+ stream = new std::basic_ostringstream<char>();
+ if (!buf.empty()) {
+ *stream << buf;
+ }
+ }
+ return *stream;
+}
+
+const std::basic_string<char>&
CharMessageBuffer::str(std::basic_ostream<char>&) {
+ buf = stream->str();
+ return buf;
+}
+
+const std::basic_string<char>& CharMessageBuffer::str(CharMessageBuffer&) {
+ return buf;
+}
+
+
+
+
#if LOG4CXX_HAS_WCHAR_T
- : wbuf(0)
-#endif
-{
+WideMessageBuffer::WideMessageBuffer() : stream(0) {}
+
+WideMessageBuffer::~WideMessageBuffer() {
+ delete stream;
+}
+
+WideMessageBuffer& WideMessageBuffer::operator<<(const
std::basic_string<wchar_t>& msg) {
+ if (stream == 0) {
+ buf.append(msg);
+ } else {
+ *stream << msg;
+ }
+ return *this;
+}
+
+WideMessageBuffer& WideMessageBuffer::operator<<(const wchar_t* msg) {
+ const wchar_t* actualMsg = msg;
+ if (actualMsg == 0) {
+ actualMsg = L"null";
+ }
+ if (stream == 0) {
+ buf.append(actualMsg);
+ } else {
+ *stream << actualMsg;
+ }
+ return *this;
+}
+
+WideMessageBuffer& WideMessageBuffer::operator<<(const wchar_t msg) {
+ if (stream == 0) {
+ buf.append(1, msg);
+ } else {
+ buf.assign(1, msg);
+ *stream << buf;
+ }
+ return *this;
+}
+
+WideMessageBuffer::operator std::basic_ostream<wchar_t>&() {
+ if (stream == 0) {
+ stream = new std::basic_ostringstream<wchar_t>();
+ if (!buf.empty()) {
+ *stream << buf;
+ }
+ }
+ return *stream;
+}
+
+const std::basic_string<wchar_t>&
WideMessageBuffer::str(std::basic_ostream<wchar_t>&) {
+ buf = stream->str();
+ return buf;
+}
+
+const std::basic_string<wchar_t>& WideMessageBuffer::str(WideMessageBuffer&) {
+ return buf;
+}
+
+
+
+
+MessageBuffer::MessageBuffer() : wbuf(0){
}
MessageBuffer::~MessageBuffer() {
-#if LOG4CXX_HAS_WCHAR_T
delete wbuf;
-#endif
-}
-
-
-CharMessageBuffer& MessageBuffer::operator<<(const std::string& msg) {
- return cbuf.operator<<(msg);
-}
-
-CharMessageBuffer& MessageBuffer::operator<<(const char* msg) {
- return cbuf.operator<<(msg);
-}
-
-CharMessageBuffer& MessageBuffer::operator<<(const char msg) {
- return cbuf.operator<<(msg);
-}
-
-const std::string& MessageBuffer::str(const CharMessageBuffer& msg) const {
- return cbuf.str(msg);
-}
-
-std::string MessageBuffer::str(const std::ostream& msg) const {
- return cbuf.str(msg);
-}
-
-
-#if LOG4CXX_HAS_WCHAR_T
-WideMessageBuffer& MessageBuffer::operator<<(const std::wstring& msg) {
- wbuf = new WideMessageBuffer(msg);
- return *wbuf;
-}
-
-WideMessageBuffer& MessageBuffer::operator<<(const wchar_t* msg) {
- if (0 == msg) {
- wbuf = new WideMessageBuffer(L"null");
- } else {
- wbuf = new WideMessageBuffer(msg);
- }
- return *wbuf;
-}
-
-WideMessageBuffer& MessageBuffer::operator<<(const wchar_t msg) {
- wbuf = new WideMessageBuffer(msg);
- return *wbuf;
-}
-
-const std::wstring& MessageBuffer::str(const WideMessageBuffer& wide) const {
- return wbuf->str(wide);
-}
-
-std::wstring MessageBuffer::str(const std::wostream& wstr) const {
- return wbuf->str(wstr);
-}
-
-WideMessageBuffer::WideMessageBuffer(const wchar_t msg) : buf(1, msg),
stream(0) {
-}
-
-WideMessageBuffer::WideMessageBuffer(const wchar_t* msg) : buf(msg), stream(0)
{
-}
-
-WideMessageBuffer::WideMessageBuffer(const std::wstring& msg) : buf(msg),
stream(0) {
-}
-
-WideMessageBuffer::~WideMessageBuffer() {
- delete stream;
-}
-
-const std::wstring& WideMessageBuffer::str(const WideMessageBuffer&) const {
- return buf;
-}
-
-std::wstring WideMessageBuffer::str(const std::wostream&) const {
- return stream->str();
-}
-
-WideMessageBuffer& WideMessageBuffer::operator<<(const std::wstring& msg) {
- buf.append(msg);
- return *this;
-}
-
-WideMessageBuffer& WideMessageBuffer::operator<<(const wchar_t* msg) {
- if (0 == msg) {
- buf.append(L"null");
- } else {
- buf.append(msg);
- }
- return *this;
-}
-
-WideMessageBuffer& WideMessageBuffer::operator<<(const wchar_t msg) {
- buf.append(1, msg);
- return *this;
-}
-
-
-
-#endif
-
-
-
+}
+
+#endif
Modified: logging/log4cxx/trunk/src/main/include/log4cxx/helpers/messagebuffer.h
URL:
http://svn.apache.org/viewvc/logging/log4cxx/trunk/src/main/include/log4cxx/helpers/messagebuffer.h?rev=592542&r1=592541&r2=592542&view=diff
==============================================================================
--- logging/log4cxx/trunk/src/main/include/log4cxx/helpers/messagebuffer.h
(original)
+++ logging/log4cxx/trunk/src/main/include/log4cxx/helpers/messagebuffer.h Tue
Nov 6 12:25:45 2007
@@ -17,327 +17,364 @@
#ifndef _LOG4CXX_MESSAGE_BUFFER_H
#define _LOG4CXX_MESSAGE_BUFFER_H
-
-#include <string>
+
#include <log4cxx/log4cxx.h>
-#include <sstream>
+#include <string>
+#include <sstream>
-namespace log4cxx {
+namespace log4cxx {
+
+
namespace helpers {
-
- /**
- * This class is used by the LOG4CXX_INFO and similar
- * macros to support insertion operators in the message parameter.
- * The class is not intended for use outside of that context.
- */
+
+
+ /**
+ * This class is used by the LOG4CXX_INFO and similar
+ * macros to support insertion operators in the message parameter.
+ * The class is not intended for use outside of that context.
+ */
class LOG4CXX_EXPORT CharMessageBuffer {
public:
/**
* Creates a new instance.
*/
- CharMessageBuffer();
+ CharMessageBuffer();
/**
* Destructor.
*/
- ~CharMessageBuffer();
+ ~CharMessageBuffer();
+
/**
* Appends string to buffer.
* @param msg string append.
* @return this buffer.
*/
- CharMessageBuffer& operator<<(const std::string& msg);
+ CharMessageBuffer& operator<<(const std::basic_string<char>& msg);
/**
* Appends string to buffer.
* @param msg string to append.
* @return this buffer.
*/
- CharMessageBuffer& operator<<(const char* msg);
- /**
- * Appends character to buffer.
- * @param msg character to append.
- * @return this buffer.
- */
- CharMessageBuffer& operator<<(const char msg);
-
- /**
- * This template allows any other insertion
- * operator to operate on an encapsulated std::ostringstream
- * created on demand.
- * @param arg instance to append.
- * @return reference to encapsulated std::ostringstream.
- */
- template<class T>
- std::ostream& operator<<(T arg) {
- stream = new std::ostringstream();
- return *stream << buf << arg;
- }
-
- /**
- * Gets the content of the encapsulated std::string.
- * @param expression insertion expression whose type is used to
- * determine whether to return the content of the encapsulated
- * std::string or the encapsulated std::ostringstream.
- * @return reference to encapsulated std::stream.
- */
- const std::string& str(const CharMessageBuffer& expression) const;
- /**
- * Gets the content of the encapsulated std::ostringstream.
- * @param expression insertion expression whose type is used to
- * determine whether to return the content of the encapsulated
- * std::string or the encapsulated std::ostringstream.
- * @return content of encapsulated std::ostringstream.
- */
- std::string str(const std::ostream& expression) const;
-
- private:
- /**
- * Prevent use of default copy constructor.
- */
- CharMessageBuffer(const CharMessageBuffer&);
- /**
- * Prevent use of default assignment operator.
- */
- CharMessageBuffer& operator=(const CharMessageBuffer&);
- /**
- * Encapsulated std::string.
- */
- std::string buf;
- /**
- * Encapsulated stream, created on demand.
- */
- std::ostringstream* stream;
- };
-
-
-
-#if LOG4CXX_HAS_WCHAR_T
- /**
- * This class is used by the LOG4CXX_INFO and similar
- * macros to support insertion operators in the message parameter.
- * The class is not intended for use outside of that context.
- */
- class LOG4CXX_EXPORT WideMessageBuffer {
- public:
- /**
- * Creates a new instance.
- * @param msg initial content of buffer.
- */
- WideMessageBuffer(const wchar_t msg);
- /**
- * Creates a new instance.
- * @param msg initial content of buffer.
- */
- WideMessageBuffer(const wchar_t* msg);
- /**
- * Creates a new instance.
- * @param msg initial content of buffer.
- */
- WideMessageBuffer(const std::wstring& msg);
- /**
- * Destructor.
- */
- ~WideMessageBuffer();
+ CharMessageBuffer& operator<<(const char* msg);
/**
- * Gets the content of the encapsulated std::wstring.
- * @param expression insertion expression whose type is used to
- * determine whether to return the content of the encapsulated
- * std::wstring or the encapsulated std::wostringstream.
- * @return reference to encapsulated std::wstream.
- */
- const std::wstring& str(const WideMessageBuffer&) const;
- /**
- * Gets the content of the encapsulated std::wostringstream.
- * @param expression insertion expression whose type is used to
- * determine whether to return the content of the encapsulated
- * std::wstring or the encapsulated std::wostringstream.
- * @return content of encapsulated std::wostringstream.
- */
- std::wstring str(const std::wostream&) const;
-
- /**
- * Appends character to buffer.
- * @param msg character to append.
- * @return this buffer.
- */
- WideMessageBuffer& operator<<(const std::wstring& msg);
- /**
- * Appends character to buffer.
- * @param msg character to append.
- * @return this buffer.
- */
- WideMessageBuffer& operator<<(const wchar_t* msg);
- /**
* Appends character to buffer.
* @param msg character to append.
* @return this buffer.
*/
- WideMessageBuffer& operator<<(const wchar_t msg);
-
- /**
- * This template allows any other insertion
- * operator to operate on an encapsulated std::wostringstream
- * created on demand.
- * @param arg instance to append.
- * @return reference to encapsulated std::wostringstream.
- */
- template<class T>
- std::wostream& operator<<(T arg) {
- stream = new std::wostringstream();
- return *stream << buf << arg;
- }
-
+ CharMessageBuffer& operator<<(const char msg);
+
+ /**
+ * Cast to ostream.
+ */
+ operator std::basic_ostream<char>&();
+
+ /**
+ * Get content of buffer.
+ * @param os used only to signal that
+ * the embedded stream was used.
+ */
+ const std::basic_string<char>& str(std::basic_ostream<char>&
os);
+
+ /**
+ * Get content of buffer.
+ * @param buf used only to signal that
+ * the embedded stream was not used.
+ */
+ const std::basic_string<char>& str(CharMessageBuffer& buf);
+
private:
/**
* Prevent use of default copy constructor.
*/
- WideMessageBuffer(const WideMessageBuffer&);
+ CharMessageBuffer(const CharMessageBuffer&);
/**
* Prevent use of default assignment operator.
*/
- WideMessageBuffer& operator=(const WideMessageBuffer&);
- /**
- * Encapsulated std::wstring.
+ CharMessageBuffer& operator=(const CharMessageBuffer&);
+
+ /**
+ * Encapsulated std::string.
*/
- std::wstring buf;
+ std::basic_string<char> buf;
/**
* Encapsulated stream, created on demand.
*/
- std::wostringstream* stream;
+ std::basic_ostringstream<char>* stream;
};
-#endif
-
+
+template<class V>
+std::basic_ostream<char>& operator<<(CharMessageBuffer& os, const V& val) {
+ return ((std::basic_ostream<char>&) os) << val;
+}
+
+inline std::basic_ostream<char>& operator<<(CharMessageBuffer& os,
std::ios_base& (*manip)(std::ios_base& s)) {
+ std::basic_ostream<char>& s = os;
+ (*manip)(s);
+ return s;
+}
+
+
+#if LOG4CXX_HAS_WCHAR_T
+ /**
+ * This class is designed to support insertion operations
+ * in the message argument to the LOG4CXX_INFO and similar
+ * macros and is not designed for general purpose use.
+ */
+ class LOG4CXX_EXPORT WideMessageBuffer {
+ public:
+ /**
+ * Creates a new instance.
+ */
+ WideMessageBuffer();
+ /**
+ * Destructor.
+ */
+ ~WideMessageBuffer();
+
+
+ /**
+ * Appends string to buffer.
+ * @param msg string append.
+ * @return this buffer.
+ */
+ WideMessageBuffer& operator<<(const std::basic_string<wchar_t>& msg);
+ /**
+ * Appends string to buffer.
+ * @param msg string to append.
+ * @return this buffer.
+ */
+ WideMessageBuffer& operator<<(const wchar_t* msg);
+
+ /**
+ * Appends character to buffer.
+ * @param msg character to append.
+ * @return this buffer.
+ */
+ WideMessageBuffer& operator<<(const wchar_t msg);
+
+ /**
+ * Cast to ostream.
+ */
+ operator std::basic_ostream<wchar_t>&();
+
+ /**
+ * Get content of buffer.
+ * @param os used only to signal that
+ * the embedded stream was used.
+ */
+ const std::basic_string<wchar_t>&
str(std::basic_ostream<wchar_t>& os);
+
+ /**
+ * Get content of buffer.
+ * @param buf used only to signal that
+ * the embedded stream was not used.
+ */
+ const std::basic_string<wchar_t>& str(WideMessageBuffer& buf);
+
+ private:
+ /**
+ * Prevent use of default copy constructor.
+ */
+ WideMessageBuffer(const WideMessageBuffer&);
+ /**
+ * Prevent use of default assignment operator.
+ */
+ WideMessageBuffer& operator=(const WideMessageBuffer&);
+
+ /**
+ * Encapsulated std::string.
+ */
+ std::basic_string<wchar_t> buf;
+ /**
+ * Encapsulated stream, created on demand.
+ */
+ std::basic_ostringstream<wchar_t>* stream;
+ };
+
+template<class V>
+std::basic_ostream<wchar_t>& operator<<(WideMessageBuffer& os, const V& val) {
+ return ((std::basic_ostream<wchar_t>&) os) << val;
+}
+
+inline std::basic_ostream<wchar_t>& operator<<(WideMessageBuffer& os,
std::ios_base& (*manip)(std::ios_base& s)) {
+ std::basic_ostream<wchar_t>& s = os;
+ (*manip)(s);
+ return s;
+}
+
+
+
/**
* This class is used by the LOG4CXX_INFO and similar
* macros to support insertion operators in the message parameter.
* The class is not intended for use outside of that context.
*/
class LOG4CXX_EXPORT MessageBuffer {
- private:
- /**
- * Prevent use of default copy constructor.
- */
- MessageBuffer(const MessageBuffer&);
- /**
- * Prevent use of default assignment operator.
- */
- MessageBuffer& operator=(const MessageBuffer&);
- /**
- * Character message buffer.
- */
- CharMessageBuffer cbuf;
public:
/**
* Creates a new instance.
*/
- MessageBuffer();
- /**
+ MessageBuffer();
+ /**
* Destructor.
*/
- ~MessageBuffer();
-
- /**
+ ~MessageBuffer();
+
+ /**
+ * Cast to ostream.
+ */
+ inline operator std::ostream&() {
+ return (std::ostream&) cbuf;
+ }
+
+ /**
+ * Appends a string into the buffer and
+ * fixes the buffer to use char characters.
+ * @param msg message to append.
+ * @return encapsulated CharMessageBuffer.
+ */
+ inline CharMessageBuffer& operator<<(const std::string& msg) {
+ return cbuf.operator<<(msg);
+ }
+ /**
+ * Appends a string into the buffer and
+ * fixes the buffer to use char characters.
+ * @param msg message to append.
+ * @return encapsulated CharMessageBuffer.
+ */
+ inline CharMessageBuffer& operator<<(const char* msg) {
+ return cbuf.operator<<(msg);
+ }
+
+ /**
+ * Appends a string into the buffer and
+ * fixes the buffer to use char characters.
+ * @param msg message to append.
+ * @return encapsulated CharMessageBuffer.
+ */
+ inline CharMessageBuffer& operator<<(const char msg) {
+ return cbuf.operator<<(msg);
+ }
+
+ /**
+ * Get content of buffer.
+ * @param buf used only to signal
+ * the character type and that
+ * the embedded stream was not used.
+ */
+ inline const std::string& str(CharMessageBuffer& buf) {
+ return cbuf.str(buf);
+ }
+
+ /**
+ * Get content of buffer.
+ * @param os used only to signal
+ * the character type and that
+ * the embedded stream was used.
+ */
+ inline const std::string& str(std::ostream& os) {
+ return cbuf.str(os);
+ }
+
+ /**
* Appends a string into the buffer and
* fixes the buffer to use char characters.
* @param msg message to append.
* @return encapsulated CharMessageBuffer.
*/
- CharMessageBuffer& operator<<(const std::string& msg);
+ inline WideMessageBuffer& operator<<(const std::wstring& msg) {
+ wbuf = new WideMessageBuffer();
+ return (*wbuf) << msg;
+ }
/**
* Appends a string into the buffer and
* fixes the buffer to use char characters.
* @param msg message to append.
* @return encapsulated CharMessageBuffer.
*/
- CharMessageBuffer& operator<<(const char* msg);
+ inline WideMessageBuffer& operator<<(const wchar_t* msg) {
+ wbuf = new WideMessageBuffer();
+ return (*wbuf) << msg;
+ }
/**
* Appends a string into the buffer and
* fixes the buffer to use char characters.
* @param msg message to append.
* @return encapsulated CharMessageBuffer.
*/
- CharMessageBuffer& operator<<(const char msg);
-
- /**
- * Gets the content of the encapsulated std::string.
- * @param expression insertion expression whose type is used to
- * determine whether to return the content of the encapsulated
- * std::string or the encapsulated std::ostringstream.
- * @return reference to encapsulated std::stream.
- */
- const std::string& str(const CharMessageBuffer&) const;
- /**
- * Gets the content of the encapsulated std::ostringstream.
- * @param expression insertion expression whose type is used to
- * determine whether to return the content of the encapsulated
- * std::string or the encapsulated std::ostringstream.
- * @return content of encapsulated std::ostringstream.
- */
- std::string str(const std::ostream&) const;
-
- /**
- * This template allows any other insertion
- * operator to operate on an encapsulated std::ostringstream
- * created on demand and fixes the buffer to use char characters.
- * @param arg instance to append.
- * @return reference to encapsulated std::ostringstream.
- */
- template<class T>
- std::ostream& operator<<(T arg) {
- return cbuf.operator<<(arg);
- }
-
-
-#if LOG4CXX_HAS_WCHAR_T
- /**
- * Appends a wide string into the buffer and
- * fixes the buffer to use wchar_t characters.
- * @param msg message to append.
- * @return encapsulated WideMessageBuffer.
- */
- WideMessageBuffer& operator<<(const std::wstring& msg);
- /**
- * Appends a wide string into the buffer and
- * fixes the buffer to use wchar_t characters.
- * @param msg message to append.
- * @return encapsulated WideMessageBuffer.
- */
- WideMessageBuffer& operator<<(const wchar_t* msg);
- /**
- * Appends a wide character into the buffer and
- * fixes the buffer to use wchar_t characters.
- * @param msg message to append.
- * @return encapsulated WideMessageBuffer.
- */
- WideMessageBuffer& operator<<(const wchar_t msg);
-
- /**
- * Gets the content of the encapsulated std::wstring.
- * @param expression insertion expression whose type is used to
- * determine whether to return the content of the encapsulated
- * std::wstring or the encapsulated std::wostringstream.
- * @return reference to encapsulated std::wstream.
- */
- const std::wstring& str(const WideMessageBuffer&) const;
- /**
- * Gets the content of the encapsulated std::wostringstream.
- * @param expression insertion expression whose type is used to
- * determine whether to return the content of the encapsulated
- * std::wstring or the encapsulated std::wostringstream.
- * @return content of encapsulated std::wostringstream.
- */
- std::wstring str(const std::wostream&) const;
-private:
+ inline WideMessageBuffer& operator<<(const wchar_t msg) {
+ wbuf = new WideMessageBuffer();
+ return (*wbuf) << msg;
+ }
+
+ /**
+ * Get content of buffer.
+ * @param buf used only to signal
+ * the character type and that
+ * the embedded stream was not used.
+ */
+ inline const std::wstring& str(WideMessageBuffer& buf) {
+ return wbuf->str(buf);
+ }
+
+ /**
+ * Get content of buffer.
+ * @param os used only to signal
+ * the character type and that
+ * the embedded stream was used.
+ */
+ inline const std::wstring& str(std::wostream& os) {
+ return wbuf->str(os);
+ }
+
+
+ private:
+ /**
+ * Prevent use of default copy constructor.
+ */
+ MessageBuffer(const MessageBuffer&);
+ /**
+ * Prevent use of default assignment operator.
+ */
+ MessageBuffer& operator=(const MessageBuffer&);
+
+ /**
+ * Character message buffer.
+ */
+ CharMessageBuffer cbuf;
+
/**
* Encapsulated wide message buffer, created on demand.
*/
WideMessageBuffer* wbuf;
-#endif
};
-}
-}
+template<class V>
+std::ostream& operator<<(MessageBuffer& os, const V& val) {
+ return ((std::ostream&) os) << val;
+}
+
+inline std::ostream& operator<<(MessageBuffer& os, std::ios_base&
(*manip)(std::ios_base& s)) {
+ std::ostream& s = os;
+ (*manip)(s);
+ return s;
+}
+
+#if LOG4CXX_LOGCHAR_IS_UTF8
+typedef CharMessageBuffer LogCharMessageBuffer;
+#endif
+
+#if LOG4CXX_LOGCHAR_IS_WCHAR
+typedef WideMessageBuffer LogCharMessageBuffer;
+#endif
+
+#else
+typedef CharMessageBuffer MessageBuffer;
+typedef CharMessageBuffer LogCharMessageBuffer;
+#endif
-#endif
+}}
+#endif
Modified: logging/log4cxx/trunk/src/main/include/log4cxx/logger.h
URL:
http://svn.apache.org/viewvc/logging/log4cxx/trunk/src/main/include/log4cxx/logger.h?rev=592542&r1=592541&r2=592542&view=diff
==============================================================================
--- logging/log4cxx/trunk/src/main/include/log4cxx/logger.h (original)
+++ logging/log4cxx/trunk/src/main/include/log4cxx/logger.h Tue Nov 6 12:25:45
2007
@@ -213,7 +213,7 @@
without further checks.
@param level the level to log.
@param message the message string to log.
- @param locaion location of the logging statement.
+ @param location location of the logging statement.
*/
void forcedLog(const LevelPtr& level, const std::string& message,
const log4cxx::spi::LocationInfo& location);
@@ -224,6 +224,15 @@
const log4cxx::spi::LocationInfo& location);
void forcedLog(const LevelPtr& level, const std::wstring& message)
const;
#endif
+ /**
+ This method creates a new logging event and logs the event
+ without further checks.
+ @param level the level to log.
+ @param message the message string to log.
+ @param location location of the logging statement.
+ */
+ void forcedLogLS(const LevelPtr& level, const LogString& message,
+ const log4cxx::spi::LocationInfo& location);
/**
Get the additivity flag for this Logger instance.
@@ -521,6 +530,8 @@
void log(const LevelPtr& level, const std::string& message,
const log4cxx::spi::LocationInfo& location);
void log(const LevelPtr& level, const std::string& message);
+ void logLS(const LevelPtr& level, const LogString& message,
+ const log4cxx::spi::LocationInfo& location);
@@ -658,6 +669,18 @@
#define LOG4CXX_LOG(logger, level, message) { \
if (logger->isEnabledFor(level)) {\
::log4cxx::helpers::MessageBuffer oss_; \
+ logger->forcedLog(level, oss_.str(oss_ << message),
LOG4CXX_LOCATION); } }
+
+/**
+Logs a message to a specified logger with a specified level.
+
[EMAIL PROTECTED] logger the logger to be used.
[EMAIL PROTECTED] level the level to log.
[EMAIL PROTECTED] message the message string to log in the internal encoding.
+*/
+#define LOG4CXX_LOGLS(logger, level, message) { \
+ if (logger->isEnabledFor(level)) {\
+ ::log4cxx::helpers::LogCharMessageBuffer oss_; \
logger->forcedLog(level, oss_.str(oss_ << message),
LOG4CXX_LOCATION); } }
/**
Modified: logging/log4cxx/trunk/src/test/cpp/asyncappendertestcase.cpp
URL:
http://svn.apache.org/viewvc/logging/log4cxx/trunk/src/test/cpp/asyncappendertestcase.cpp?rev=592542&r1=592541&r2=592542&view=diff
==============================================================================
--- logging/log4cxx/trunk/src/test/cpp/asyncappendertestcase.cpp (original)
+++ logging/log4cxx/trunk/src/test/cpp/asyncappendertestcase.cpp Tue Nov 6
12:25:45 2007
@@ -82,10 +82,10 @@
//
if (event->getLevel() == Level::getInfo()) {
LoggerPtr logger = Logger::getLogger(event->getLoggerName());
- LOG4CXX_ERROR(logger, event->getMessage());
- LOG4CXX_WARN(logger, event->getMessage());
- LOG4CXX_INFO(logger, event->getMessage());
- LOG4CXX_DEBUG(logger, event->getMessage());
+ LOG4CXX_LOGLS(logger, Level::getError(), event->getMessage());
+ LOG4CXX_LOGLS(logger, Level::getWarn(), event->getMessage());
+ LOG4CXX_LOGLS(logger, Level::getInfo(), event->getMessage());
+ LOG4CXX_LOGLS(logger, Level::getDebug(), event->getMessage());
}
}
Modified: logging/log4cxx/trunk/src/test/cpp/net/socketservertestcase.cpp
URL:
http://svn.apache.org/viewvc/logging/log4cxx/trunk/src/test/cpp/net/socketservertestcase.cpp?rev=592542&r1=592541&r2=592542&view=diff
==============================================================================
--- logging/log4cxx/trunk/src/test/cpp/net/socketservertestcase.cpp (original)
+++ logging/log4cxx/trunk/src/test/cpp/net/socketservertestcase.cpp Tue Nov 6
12:25:45 2007
@@ -458,23 +458,21 @@
int i = -1;
NDC::push(dc);
MDC::put(key, val);
- Pool p;
i++;
- LogString msg(LOG4CXX_STR("Message "));
+ std::string msg("Message ");
- LOG4CXX_LOG(logger, XLevel::TRACE,
- msg + StringHelper::toString(i, p));
+ LOG4CXX_LOG(logger, XLevel::TRACE, msg << i);
i++;
- LOG4CXX_DEBUG(logger, msg + StringHelper::toString(i, p));
+ LOG4CXX_DEBUG(logger, msg << i);
i++;
- LOG4CXX_DEBUG(root, msg + StringHelper::toString(i, p));
+ LOG4CXX_DEBUG(root, msg << i);
i++;
- LOG4CXX_INFO(logger, msg + StringHelper::toString(i, p));
+ LOG4CXX_INFO(logger, msg << i);
i++;
- LOG4CXX_WARN(logger, msg + StringHelper::toString(i, p));
+ LOG4CXX_WARN(logger, msg << i);
i++;
- LOG4CXX_LOG(logger, XLevel::LETHAL, msg +
StringHelper::toString(i, p)); //5
+ LOG4CXX_LOG(logger, XLevel::LETHAL, msg << i); //5
NDC::pop();
MDC::remove(key);
Modified: logging/log4cxx/trunk/src/test/cpp/shortsocketserver.cpp
URL:
http://svn.apache.org/viewvc/logging/log4cxx/trunk/src/test/cpp/shortsocketserver.cpp?rev=592542&r1=592541&r2=592542&view=diff
==============================================================================
--- logging/log4cxx/trunk/src/test/cpp/shortsocketserver.cpp (original)
+++ logging/log4cxx/trunk/src/test/cpp/shortsocketserver.cpp Tue Nov 6
12:25:45 2007
@@ -78,9 +78,9 @@
PropertyConfigurator::configure(sbuf.str());
LOG4CXX_INFO(log, "Waiting to accept a new client.");
SocketPtr socket = serverSocket.accept();
- LogString msg(socket->getInetAddress()->toString());
- msg.insert(0, LOG4CXX_STR("Connected to client at "));
- LOG4CXX_INFO(log, msg);
+ LOG4CXX_LOGLS(log, Level::getInfo(),
+ LOG4CXX_STR("Connected to client at ")
+ << socket->getInetAddress()->toString());
LOG4CXX_INFO(log, "Starting new socket node.");
SocketNode sn(socket, LogManager::getLoggerRepository());
sn.run();
Modified: logging/log4cxx/trunk/src/test/cpp/streamtestcase.cpp
URL:
http://svn.apache.org/viewvc/logging/log4cxx/trunk/src/test/cpp/streamtestcase.cpp?rev=592542&r1=592541&r2=592542&view=diff
==============================================================================
--- logging/log4cxx/trunk/src/test/cpp/streamtestcase.cpp (original)
+++ logging/log4cxx/trunk/src/test/cpp/streamtestcase.cpp Tue Nov 6 12:25:45
2007
@@ -23,6 +23,7 @@
#include <log4cxx/logmanager.h>
#include <log4cxx/simplelayout.h>
#include <log4cxx/spi/loggingevent.h>
+#include "insertwide.h"
using namespace log4cxx;
using namespace log4cxx::helpers;
@@ -130,7 +131,7 @@
LOG4CXX_INFO(root, '[' << std::fixed << std::setprecision(2) <<
std::setw(7) << std::right << std::setfill('_') << 10.0 << ']');
spi::LoggingEventPtr event(vectorAppender->getVector()[0]);
LogString msg(event->getMessage());
- CPPUNIT_ASSERT(msg == LOG4CXX_STR("[__10.00]"));
+ CPPUNIT_ASSERT_EQUAL(LogString(LOG4CXX_STR("[__10.00]")), msg);
}
#if LOG4CXX_HAS_WCHAR_T
@@ -148,10 +149,10 @@
void testWideWidth() {
LoggerPtr root(Logger::getRootLogger());
- LOG4CXX_INFO(root, L'[' << std::fixed << std::setprecision(2) <<
std::setw(7) << std::right << std::setfill(L'_') << 10.0 << L']');
+ LOG4CXX_INFO(root, L'[' << std::fixed << std::setprecision(2) <<
std::setw(7) << std::right << std::setfill(L'_') << 10.0 << L"]");
spi::LoggingEventPtr event(vectorAppender->getVector()[0]);
LogString msg(event->getMessage());
- CPPUNIT_ASSERT(msg == LOG4CXX_STR("[__10.00]"));
+ CPPUNIT_ASSERT_EQUAL(LogString(LOG4CXX_STR("[__10.00]")), msg);
}
#endif
};
Modified: logging/log4cxx/trunk/src/test/cpp/xml/xmllayouttestcase.cpp
URL:
http://svn.apache.org/viewvc/logging/log4cxx/trunk/src/test/cpp/xml/xmllayouttestcase.cpp?rev=592542&r1=592541&r2=592542&view=diff
==============================================================================
--- logging/log4cxx/trunk/src/test/cpp/xml/xmllayouttestcase.cpp (original)
+++ logging/log4cxx/trunk/src/test/cpp/xml/xmllayouttestcase.cpp Tue Nov 6
12:25:45 2007
@@ -313,23 +313,22 @@
int i = -1;
X x;
- Pool p;
- LogString msg(LOG4CXX_STR("Message "));
+ std::string msg("Message ");
- LOG4CXX_DEBUG(logger, msg + StringHelper::toString(++i, p));
- LOG4CXX_DEBUG(root, msg + StringHelper::toString(i, p));
+ LOG4CXX_DEBUG(logger, msg << ++i);
+ LOG4CXX_DEBUG(root, msg << i);
- LOG4CXX_INFO(logger, msg + StringHelper::toString(++i, p));
- LOG4CXX_INFO(root, msg + StringHelper::toString(i,p));
+ LOG4CXX_INFO(logger, msg << ++i);
+ LOG4CXX_INFO(root, msg << i);
- LOG4CXX_WARN(logger, msg + StringHelper::toString(++i, p));
- LOG4CXX_WARN(root, msg + StringHelper::toString(i, p));
+ LOG4CXX_WARN(logger, msg << ++i);
+ LOG4CXX_WARN(root, msg << i);
- LOG4CXX_ERROR(logger, msg + StringHelper::toString(++i, p));
- LOG4CXX_ERROR(root, msg + StringHelper::toString(i, p));
+ LOG4CXX_ERROR(logger, msg << ++i);
+ LOG4CXX_ERROR(root, msg << i);
- LOG4CXX_FATAL(logger, msg + StringHelper::toString(++i, p));
- LOG4CXX_FATAL(root, msg + StringHelper::toString(i, p));
+ LOG4CXX_FATAL(logger, msg << ++i);
+ LOG4CXX_FATAL(root, msg << i);
}
};