You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4cxx-dev@logging.apache.org by ca...@apache.org on 2007/12/05 21:59:09 UTC
svn commit: r601521 - in /logging/log4cxx/trunk/src/main: cpp/
include/log4cxx/ include/log4cxx/spi/
Author: carnold
Date: Wed Dec 5 12:59:01 2007
New Revision: 601521
URL: http://svn.apache.org/viewvc?rev=601521&view=rev
Log:
LOGCXX-210: HTMLLayout NDC null check
Modified:
logging/log4cxx/trunk/src/main/cpp/asyncappender.cpp
logging/log4cxx/trunk/src/main/cpp/htmllayout.cpp
logging/log4cxx/trunk/src/main/cpp/loggingevent.cpp
logging/log4cxx/trunk/src/main/cpp/mdc.cpp
logging/log4cxx/trunk/src/main/cpp/ndc.cpp
logging/log4cxx/trunk/src/main/cpp/ndcpatternconverter.cpp
logging/log4cxx/trunk/src/main/cpp/propertiespatternconverter.cpp
logging/log4cxx/trunk/src/main/cpp/ttcclayout.cpp
logging/log4cxx/trunk/src/main/cpp/xmllayout.cpp
logging/log4cxx/trunk/src/main/include/log4cxx/mdc.h
logging/log4cxx/trunk/src/main/include/log4cxx/ndc.h
logging/log4cxx/trunk/src/main/include/log4cxx/spi/loggingevent.h
Modified: logging/log4cxx/trunk/src/main/cpp/asyncappender.cpp
URL: http://svn.apache.org/viewvc/logging/log4cxx/trunk/src/main/cpp/asyncappender.cpp?rev=601521&r1=601520&r2=601521&view=diff
==============================================================================
--- logging/log4cxx/trunk/src/main/cpp/asyncappender.cpp (original)
+++ logging/log4cxx/trunk/src/main/cpp/asyncappender.cpp Wed Dec 5 12:59:01 2007
@@ -96,7 +96,8 @@
// Set the NDC and thread name for the calling thread as these
// LoggingEvent fields were not set at event creation time.
- event->getNDC();
+ LogString ndcVal;
+ event->getNDC(ndcVal);
event->getThreadName();
// Get a copy of this thread's MDC.
event->getMDCCopy();
Modified: logging/log4cxx/trunk/src/main/cpp/htmllayout.cpp
URL: http://svn.apache.org/viewvc/logging/log4cxx/trunk/src/main/cpp/htmllayout.cpp?rev=601521&r1=601520&r2=601521&view=diff
==============================================================================
--- logging/log4cxx/trunk/src/main/cpp/htmllayout.cpp (original)
+++ logging/log4cxx/trunk/src/main/cpp/htmllayout.cpp Wed Dec 5 12:59:01 2007
@@ -125,13 +125,14 @@
output.append(LOG4CXX_STR("</td>") LOG4CXX_EOL);
output.append(LOG4CXX_STR("</tr>") LOG4CXX_EOL);
- if (event->getNDC().length() != 0)
+ LogString ndcVal;
+ if (event->getNDC(ndcVal))
{
output.append(LOG4CXX_STR("<tr><td bgcolor=\"#EEEEEE\" "));
output.append(LOG4CXX_STR("style=\"font-size : xx-small;\" colspan=\"6\" "));
output.append(LOG4CXX_STR("title=\"Nested Diagnostic Context\">"));
output.append(LOG4CXX_STR("NDC: "));
- Transform::appendEscapingTags(output, event->getNDC());
+ Transform::appendEscapingTags(output, ndcVal);
output.append(LOG4CXX_STR("</td></tr>") LOG4CXX_EOL);
}
}
Modified: logging/log4cxx/trunk/src/main/cpp/loggingevent.cpp
URL: http://svn.apache.org/viewvc/logging/log4cxx/trunk/src/main/cpp/loggingevent.cpp?rev=601521&r1=601520&r2=601521&view=diff
==============================================================================
--- logging/log4cxx/trunk/src/main/cpp/loggingevent.cpp (original)
+++ logging/log4cxx/trunk/src/main/cpp/loggingevent.cpp Wed Dec 5 12:59:01 2007
@@ -48,7 +48,7 @@
}
LoggingEvent::LoggingEvent() :
- ndc(LOG4CXX_STR("null")),
+ ndc(0),
properties(0),
ndcLookupRequired(true),
mdcCopyLookupRequired(true),
@@ -61,7 +61,7 @@
const LogString& message1, const LocationInfo& locationInfo1) :
logger(logger1),
level(level1),
- ndc(LOG4CXX_STR("null")),
+ ndc(0),
properties(0),
ndcLookupRequired(true),
mdcCopyLookupRequired(true),
@@ -73,10 +73,8 @@
LoggingEvent::~LoggingEvent()
{
- if (properties != 0)
- {
- delete properties;
- }
+ delete ndc;
+ delete properties;
}
const LogString LoggingEvent::getLoggerName() const
@@ -84,18 +82,24 @@
return logger->getName();
}
-const LogString& LoggingEvent::getNDC() const
+bool LoggingEvent::getNDC(LogString& dest) const
{
if(ndcLookupRequired)
{
ndcLookupRequired = false;
- ndc = NDC::get();
+ LogString val;
+ if(NDC::get(val)) {
+ ndc = new LogString(val);
+ }
}
-
- return ndc;
+ if (ndc) {
+ dest.append(*ndc);
+ return true;
+ }
+ return false;
}
-LogString LoggingEvent::getMDC(const LogString& key) const
+bool LoggingEvent::getMDC(const LogString& key, LogString& dest) const
{
// Note the mdcCopy is used if it exists. Otherwise we use the MDC
// that is associated with the thread.
@@ -107,12 +111,13 @@
{
if (!it->second.empty())
{
- return it->second;
+ dest.append(it->second);
+ return true;
}
}
}
- return MDC::get(key);
+ return MDC::get(key, dest);
}
@@ -153,26 +158,22 @@
}
}
-LogString LoggingEvent::getProperty(const LogString& key) const
+bool LoggingEvent::getProperty(const LogString& key, LogString& dest) const
{
if (properties == 0)
{
- return LogString();
+ return false;
}
std::map<LogString, LogString>::const_iterator it = properties->find(key);
if (it != properties->end())
{
- const LogString& p = it->second;
-
- if (!p.empty())
- {
- return p;
- }
+ dest.append(it->second);
+ return true;
}
- return LogString();
+ return false;
}
std::set<LogString> LoggingEvent::getPropertyKeySet() const
@@ -291,10 +292,10 @@
} else {
os.writeObject(mdcCopy, p);
}
- if (ndc.size() == 0) {
+ if (ndc == 0) {
os.writeByte(ObjectOutputStream::TC_NULL, p);
} else {
- os.writeObject(ndc, p);
+ os.writeObject(*ndc, p);
}
os.writeObject(message, p);
os.writeObject(threadName, p);
Modified: logging/log4cxx/trunk/src/main/cpp/mdc.cpp
URL: http://svn.apache.org/viewvc/logging/log4cxx/trunk/src/main/cpp/mdc.cpp?rev=601521&r1=601520&r2=601521&view=diff
==============================================================================
--- logging/log4cxx/trunk/src/main/cpp/mdc.cpp (original)
+++ logging/log4cxx/trunk/src/main/cpp/mdc.cpp Wed Dec 5 12:59:01 2007
@@ -60,7 +60,7 @@
Map::iterator it = map.find(key);
if (it != map.end()) {
- value = it->second;
+ value.append(it->second);
return true;
}
return false;
Modified: logging/log4cxx/trunk/src/main/cpp/ndc.cpp
URL: http://svn.apache.org/viewvc/logging/log4cxx/trunk/src/main/cpp/ndc.cpp?rev=601521&r1=601520&r2=601521&view=diff
==============================================================================
--- logging/log4cxx/trunk/src/main/cpp/ndc.cpp (original)
+++ logging/log4cxx/trunk/src/main/cpp/ndc.cpp Wed Dec 5 12:59:01 2007
@@ -74,37 +74,15 @@
}
}
-#if 0
-NDC::Stack * NDC::cloneStack()
-{
- Stack * stack = getCurrentThreadStack();
- if(stack != 0)
- {
- return new Stack(*stack);
- }
- else
- {
- return new Stack();
- }
-}
-
-void NDC::inherit(NDC::Stack * stack)
-{
- if(stack != 0)
- {
- setCurrentThreadStack(stack);
- }
-}
-
-#endif
-LogString NDC::get()
+bool NDC::get(LogString& dest)
{
Stack& stack = ThreadSpecificData::getCurrentThreadStack();
if(!stack.empty())
{
- return stack.top().fullMessage;
+ dest.append(stack.top().fullMessage);
+ return true;
}
- return getNull();
+ return false;
}
int NDC::getDepth()
@@ -121,7 +99,7 @@
stack.pop();
return value;
}
- return getNull();
+ return LOG4CXX_STR("");
}
LogString NDC::peek()
@@ -131,7 +109,7 @@
{
return stack.top().message;
}
- return getNull();
+ return LOG4CXX_STR("");
}
void NDC::pushLogString(const LogString& message)
@@ -173,12 +151,3 @@
return stack.empty();
}
-bool NDC::isNull(const LogString& str) {
- return str == getNull();
-}
-
-
-const LogString& NDC::getNull() {
- static LogString nullStr(LOG4CXX_STR("null"));
- return nullStr;
-}
Modified: logging/log4cxx/trunk/src/main/cpp/ndcpatternconverter.cpp
URL: http://svn.apache.org/viewvc/logging/log4cxx/trunk/src/main/cpp/ndcpatternconverter.cpp?rev=601521&r1=601520&r2=601521&view=diff
==============================================================================
--- logging/log4cxx/trunk/src/main/cpp/ndcpatternconverter.cpp (original)
+++ logging/log4cxx/trunk/src/main/cpp/ndcpatternconverter.cpp Wed Dec 5 12:59:01 2007
@@ -45,5 +45,7 @@
const LoggingEventPtr& event,
LogString& toAppendTo,
Pool& /* p */) const {
- toAppendTo.append(event->getNDC());
+ if(!event->getNDC(toAppendTo)) {
+ toAppendTo.append(LOG4CXX_STR("null"));
+ }
}
Modified: logging/log4cxx/trunk/src/main/cpp/propertiespatternconverter.cpp
URL: http://svn.apache.org/viewvc/logging/log4cxx/trunk/src/main/cpp/propertiespatternconverter.cpp?rev=601521&r1=601520&r2=601521&view=diff
==============================================================================
--- logging/log4cxx/trunk/src/main/cpp/propertiespatternconverter.cpp (original)
+++ logging/log4cxx/trunk/src/main/cpp/propertiespatternconverter.cpp Wed Dec 5 12:59:01 2007
@@ -64,14 +64,14 @@
toAppendTo.append(1, LOG4CXX_STR('{'));
toAppendTo.append(*iter);
toAppendTo.append(1, LOG4CXX_STR(','));
- toAppendTo.append(event->getMDC(*iter));
+ event->getMDC(*iter, toAppendTo);
toAppendTo.append(1, LOG4CXX_STR('}'));
}
toAppendTo.append(1, LOG4CXX_STR('}'));
} else {
- toAppendTo.append(event->getMDC(option));
+ event->getMDC(option, toAppendTo);
}
}
Modified: logging/log4cxx/trunk/src/main/cpp/ttcclayout.cpp
URL: http://svn.apache.org/viewvc/logging/log4cxx/trunk/src/main/cpp/ttcclayout.cpp?rev=601521&r1=601520&r2=601521&view=diff
==============================================================================
--- logging/log4cxx/trunk/src/main/cpp/ttcclayout.cpp (original)
+++ logging/log4cxx/trunk/src/main/cpp/ttcclayout.cpp Wed Dec 5 12:59:01 2007
@@ -65,15 +65,8 @@
output.append(1, LOG4CXX_STR(' '));
}
- if(contextPrinting)
- {
- LogString ndc = event->getNDC();
-
- if(!NDC::isNull(ndc))
- {
- output.append(ndc);
- output.append(1, LOG4CXX_STR(' '));
- }
+ if(contextPrinting && event->getNDC(output)) {
+ output.append(1, LOG4CXX_STR(' '));
}
output.append(LOG4CXX_STR("- "));
Modified: logging/log4cxx/trunk/src/main/cpp/xmllayout.cpp
URL: http://svn.apache.org/viewvc/logging/log4cxx/trunk/src/main/cpp/xmllayout.cpp?rev=601521&r1=601520&r2=601521&view=diff
==============================================================================
--- logging/log4cxx/trunk/src/main/cpp/xmllayout.cpp (original)
+++ logging/log4cxx/trunk/src/main/cpp/xmllayout.cpp Wed Dec 5 12:59:01 2007
@@ -68,9 +68,8 @@
Transform::appendEscapingCDATA(output, event->getRenderedMessage());
output.append(LOG4CXX_STR("]]></log4j:message>") LOG4CXX_EOL);
- const LogString& ndc = event->getNDC();
- if(!NDC::isNull(ndc))
- {
+ LogString ndc;
+ if(event->getNDC(ndc)) {
output.append(LOG4CXX_STR("<log4j:NDC><![CDATA["));
output.append(ndc);
output.append(LOG4CXX_STR("]]></log4j:NDC>") LOG4CXX_EOL);
@@ -95,12 +94,14 @@
i != mdcKeySet.end(); i++)
{
LogString propName = *i;
- LogString propValue = event->getMDC(propName);
- output.append(LOG4CXX_STR(" <log4j:data name=\""));
- output.append(propName);
- output.append(LOG4CXX_STR("\" value=\""));
- output.append(propValue);
- output.append(LOG4CXX_STR("\"/>") LOG4CXX_EOL);
+ LogString propValue;
+ if(event->getMDC(propName, propValue)) {
+ output.append(LOG4CXX_STR(" <log4j:data name=\""));
+ output.append(propName);
+ output.append(LOG4CXX_STR("\" value=\""));
+ output.append(propValue);
+ output.append(LOG4CXX_STR("\"/>") LOG4CXX_EOL);
+ }
}
output.append(LOG4CXX_STR("</log4j:MDC>") LOG4CXX_EOL);
}
@@ -131,12 +132,14 @@
i != propertySet.end(); i++)
{
LogString propName = *i;
- output .append(LOG4CXX_STR("<log4j:data name=\""));
- output.append(propName);
- LogString propValue = event->getProperty(propName);
- output.append(LOG4CXX_STR("\" value=\""));
- output.append(propValue);
- output.append(LOG4CXX_STR("\"/>") LOG4CXX_EOL);
+ LogString propValue;
+ if(event->getProperty(propName, propValue)) {
+ output.append(LOG4CXX_STR("<log4j:data name=\""));
+ output.append(propName);
+ output.append(LOG4CXX_STR("\" value=\""));
+ output.append(propValue);
+ output.append(LOG4CXX_STR("\"/>") LOG4CXX_EOL);
+ }
}
output.append(LOG4CXX_STR("</log4j:properties>") LOG4CXX_EOL);
}
Modified: logging/log4cxx/trunk/src/main/include/log4cxx/mdc.h
URL: http://svn.apache.org/viewvc/logging/log4cxx/trunk/src/main/include/log4cxx/mdc.h?rev=601521&r1=601520&r2=601521&view=diff
==============================================================================
--- logging/log4cxx/trunk/src/main/include/log4cxx/mdc.h (original)
+++ logging/log4cxx/trunk/src/main/include/log4cxx/mdc.h Wed Dec 5 12:59:01 2007
@@ -74,7 +74,13 @@
static std::wstring get(const std::wstring& key);
#endif
static std::string get(const std::string& key);
- static bool get(const LogString& key, LogString& value);
+ /**
+ * Gets the context identified by the <code>key</code> parameter.
+ * @param key context key.
+ * @param dest destination to which value is appended.
+ * @return true if key has associated value.
+ */
+ static bool get(const LogString& key, LogString& dest);
/**
* Remove the the context identified by the <code>key</code>
@@ -89,14 +95,6 @@
* Clear all entries in the MDC.
*/
static void clear();
-
- /**
- * Get the current thread's MDC as a Map. This method is
- * intended to be used internally.
- * */
-// static const Map getContext();
-
-// static void setContext(Map& map);
}; // class MDC;
} // namespace log4cxx
Modified: logging/log4cxx/trunk/src/main/include/log4cxx/ndc.h
URL: http://svn.apache.org/viewvc/logging/log4cxx/trunk/src/main/include/log4cxx/ndc.h?rev=601521&r1=601520&r2=601521&view=diff
==============================================================================
--- logging/log4cxx/trunk/src/main/include/log4cxx/ndc.h (original)
+++ logging/log4cxx/trunk/src/main/include/log4cxx/ndc.h Wed Dec 5 12:59:01 2007
@@ -24,9 +24,6 @@
namespace log4cxx
{
- class DiagnosticContext;
- typedef std::stack<DiagnosticContext> Stack;
-
/**
the ndc class implements <i>nested diagnostic contexts</i> as
defined by neil harrison in the article "patterns for logging
@@ -146,41 +143,15 @@
*/
static void clear();
- /**
- Clone the diagnostic context for the current thread.
- <p>Internally a diagnostic context is represented as a stack. A
- given thread can supply the stack (i.e. diagnostic context) to a
- child thread so that the child can inherit the parent thread's
- diagnostic context.
- <p>The child thread uses the #inherit method to
- inherit the parent's diagnostic context.
- @return Stack A clone of the current thread's diagnostic context.
- */
-// static Stack * cloneStack();
-
- /**
- Inherit the diagnostic context of another thread.
- <p>The parent thread can obtain a reference to its diagnostic
- context using the #cloneStack method. It should
- communicate this information to its child so that it may inherit
- the parent's diagnostic context.
- <p>The parent's diagnostic context is cloned before being
- inherited. In other words, once inherited, the two diagnostic
- contexts can be managed independently.
- <p>In java, a child thread cannot obtain a reference to its
- parent, unless it is directly handed the reference. Consequently,
- there is no client-transparent way of inheriting diagnostic
- contexts. Do you know any solution to this problem?
- @param stack The diagnostic context of the parent thread.
- */
-// static void inherit(Stack * stack);
/**
<b>Never use this method directly, use the
{@link spi::LoggingEvent#getNDC LoggingEvent::getNDC}
method instead.</b>
+ * @param dest destination to which to append content of NDC.
+ * @return true if NDC is set.
*/
- static LogString get();
+ static bool get(LogString& dest);
/**
Get the current nesting depth of this diagnostic context.
@@ -198,7 +169,7 @@
context.
<p>The returned value is the value that was pushed last. If no
context is available, then the empty string "" is returned.
- @return String The innermost diagnostic context.
+ @return The innermost diagnostic context.
*/
static LogString pop();
@@ -240,19 +211,6 @@
memory.
*/
static void remove();
-
-
- /**
- * Tests if the specified string is the value
- * (usually "null") returned when the NDC is empty.
- */
- static bool isNull(const LogString& str);
-
- private:
- /**
- * Get the string returned when the NDC is empty.
- */
- static const LogString& getNull();
}; // class NDC;
} // namespace log4cxx
Modified: logging/log4cxx/trunk/src/main/include/log4cxx/spi/loggingevent.h
URL: http://svn.apache.org/viewvc/logging/log4cxx/trunk/src/main/include/log4cxx/spi/loggingevent.h?rev=601521&r1=601520&r2=601521&view=diff
==============================================================================
--- logging/log4cxx/trunk/src/main/include/log4cxx/spi/loggingevent.h (original)
+++ logging/log4cxx/trunk/src/main/include/log4cxx/spi/loggingevent.h Wed Dec 5 12:59:01 2007
@@ -118,11 +118,15 @@
{ return locationInfo; }
/**
- * This method returns the NDC for this event. It will return the
+ * This method appends the NDC for this event to passed string. It will return the
* correct content even if the event was generated in a different
* thread or even on a different machine. The NDC#get method
- * should <em>never</em> be called directly. */
- const LogString& getNDC() const;
+ * should <em>never</em> be called directly.
+ *
+ * @param dest destination for NDC, unchanged if NDC is not set.
+ * @return true if NDC is set.
+ */
+ bool getNDC(LogString& dest) const;
/**
* Writes the content of the LoggingEvent
@@ -131,7 +135,7 @@
void write(helpers::ObjectOutputStream& os, helpers::Pool& p) const;
/**
- * Returns the the context corresponding to the <code>key</code> parameter.
+ * Appends the the context corresponding to the <code>key</code> parameter.
* If there is a local MDC copy, possibly because we are in a logging
* server or running inside AsyncAppender, then we search for the key in
* MDC copy, if a value is found it is returned. Otherwise, if the search
@@ -142,8 +146,11 @@
* Note that <em>both</em> the local MDC copy and the current thread's MDC
* are searched.
* </p>
+ * @param key key.
+ * @param dest string to which value, if any, is appended.
+ * @return true if key had a corresponding value.
*/
- LogString getMDC(const LogString& key) const;
+ bool getMDC(const LogString& key, LogString& dest) const;
/**
* Returns the set of of the key values in the MDC for the event.
@@ -161,9 +168,12 @@
void getMDCCopy() const;
/**
- * Return a previously set property. The return value can be null.
+ * Return a previously set property.
+ * @param key key.
+ * @param dest string to which value, if any, is appended.
+ * @return true if key had a corresponding value.
*/
- LogString getProperty(const LogString& key) const;
+ bool getProperty(const LogString& key, LogString& dest) const;
/**
* Returns the set of of the key values in the properties
* for the event. The returned set is unmodifiable by the caller.
@@ -198,7 +208,7 @@
LevelPtr level;
/** The nested diagnostic context (NDC) of logging event. */
- mutable LogString ndc;
+ mutable LogString* ndc;
/** The mapped diagnostic context (MDC) of logging event. */
mutable MDC::Map mdcCopy;