Am Sonntag, 19. Dezember 2004 09:45 schrieb Tommi M�kitalo:
> Am Sonntag, 19. Dezember 2004 07:11 schrieb Curt Arnold:
> > On Dec 18, 2004, at 6:19 PM, Curt Arnold wrote:
> > >> Just to fight at least a little for STL (I don't want to start a
> > >> flame-war
> > >> about STL): I created StringHelper::UlongToString-methods and
> > >> benchmarked it
> > >> against std::wostringstream. The result was, that for large numbers
> > >> (>INT_MAX, where your optimization don't catch), it took 2.3 seconds
> > >> to
> > >> format 1000000 with UlongToString and 1.5 seconds with
> > >> std::wostringstream
> > >> (including std::wostringstream-creation). For small numbers
> > >> UlongToString
> > >> took 0.5 seconds.
> >
> > For thread id it is probably more useful to output hex, since any
> > debugger would be unlikely to display a signed decimal representation
> > (plus it is very simple to implement).
>
> hex sounds good. When I saw my 64-bit thread-id I thought it looked
> somewhat funny. And yes - the implementation will get much easier. I will
> try that.
>
> Tommi
Here is the patch for logging thread-ids in hex.

I used basic_string::reserve here. Might improve performance when generating 
logmessages also. I will check.


Tommi
Index: include/log4cxx/helpers/stringhelper.h
===================================================================
RCS file: /home/cvspublic/logging-log4cxx/include/log4cxx/helpers/stringhelper.h,v
retrieving revision 1.15
diff -u -r1.15 stringhelper.h
--- include/log4cxx/helpers/stringhelper.h	18 Dec 2004 08:28:28 -0000	1.15
+++ include/log4cxx/helpers/stringhelper.h	19 Dec 2004 20:07:18 -0000
@@ -56,6 +56,8 @@
             static LogString toString(int s, apr_pool_t* pool);
             static LogString toString(int s);
 
+            static LogString ULongToHex(unsigned long s);
+
             static std::string toLowerCase(const std::string& s);
             static std::wstring toLowerCase(const std::wstring& s);
 
Index: src/htmllayout.cpp
===================================================================
RCS file: /home/cvspublic/logging-log4cxx/src/htmllayout.cpp,v
retrieving revision 1.15
diff -u -r1.15 htmllayout.cpp
--- src/htmllayout.cpp	11 Dec 2004 04:53:25 -0000	1.15
+++ src/htmllayout.cpp	19 Dec 2004 20:07:18 -0000
@@ -26,7 +26,6 @@
 #include <apr_pools.h>
 #include <apr_time.h>
 #include <apr_strings.h>
-#include <string.h>
 
 using namespace log4cxx;
 using namespace log4cxx::helpers;
@@ -72,7 +71,7 @@
         output.append(LOG4CXX_STR("</td>\n"));
 
         output.append(LOG4CXX_STR("<td title=\""));
-        LogString threadId(StringHelper::toString(event->getThreadId(), pool));
+        LogString threadId(StringHelper::ULongToHex(event->getThreadId()));
         output.append(threadId);
         output.append(LOG4CXX_STR(" thread\">"));
         output.append(threadId);
Index: src/ttcclayout.cpp
===================================================================
RCS file: /home/cvspublic/logging-log4cxx/src/ttcclayout.cpp,v
retrieving revision 1.12
diff -u -r1.12 ttcclayout.cpp
--- src/ttcclayout.cpp	11 Dec 2004 04:53:25 -0000	1.12
+++ src/ttcclayout.cpp	19 Dec 2004 20:07:18 -0000
@@ -49,7 +49,7 @@
 	if(threadPrinting)
 	{
                 output.append(1, LOG4CXX_STR('['));
-                output.append(StringHelper::toString(event->getThreadId(), p));
+                output.append(StringHelper::ULongToHex(event->getThreadId()));
                 output.append(LOG4CXX_STR("] "));
 	}
 
Index: src/xmllayout.cpp
===================================================================
RCS file: /home/cvspublic/logging-log4cxx/src/xmllayout.cpp,v
retrieving revision 1.18
diff -u -r1.18 xmllayout.cpp
--- src/xmllayout.cpp	11 Dec 2004 04:53:25 -0000	1.18
+++ src/xmllayout.cpp	19 Dec 2004 20:07:19 -0000
@@ -56,7 +56,7 @@
 	output.append(LOG4CXX_STR("\" level=\""));
 	output.append(event->getLevel()->toString());
 	output.append(LOG4CXX_STR("\" thread=\""));
-	output.append(StringHelper::toString(event->getThreadId(), p));
+	output.append(StringHelper::ULongToHex(event->getThreadId()));
 	output.append(LOG4CXX_STR("\">\n"));
 
 	output.append(LOG4CXX_STR("<log4j:message><![CDATA["));

Reply via email to