You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by sw...@apache.org on 2023/12/26 06:22:52 UTC
(logging-log4cxx) branch no_thread_name created (now 41d81106)
This is an automated email from the ASF dual-hosted git repository.
swebb2066 pushed a change to branch no_thread_name
in repository https://gitbox.apache.org/repos/asf/logging-log4cxx.git
at 41d81106 Use '(noname)' for an unnamed thread when the layout requires a thread name
This branch includes the following new commits:
new 41d81106 Use '(noname)' for an unnamed thread when the layout requires a thread name
The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
(logging-log4cxx) 01/01: Use '(noname)' for an unnamed thread when the layout requires a thread name
Posted by sw...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
swebb2066 pushed a commit to branch no_thread_name
in repository https://gitbox.apache.org/repos/asf/logging-log4cxx.git
commit 41d81106234fa65c8264726e2d9d1ec6ca378381
Author: Stephen Webb <sw...@gmail.com>
AuthorDate: Tue Dec 26 17:22:15 2023 +1100
Use '(noname)' for an unnamed thread when the layout requires a thread name
---
src/main/cpp/loggingevent.cpp | 17 ++++++++---------
1 file changed, 8 insertions(+), 9 deletions(-)
diff --git a/src/main/cpp/loggingevent.cpp b/src/main/cpp/loggingevent.cpp
index 129d196f..e4a30e84 100644
--- a/src/main/cpp/loggingevent.cpp
+++ b/src/main/cpp/loggingevent.cpp
@@ -371,13 +371,13 @@ const LogString& LoggingEvent::getCurrentThreadName()
#if defined(_WIN32)
char result[20];
apr_snprintf(result, sizeof(result), LOG4CXX_WIN32_THREAD_FMTSPEC, threadId);
- Transcoder::decode(reinterpret_cast<const char*>(result), thread_id_string);
+ thread_id_string = Transcoder::decode(result);
#elif LOG4CXX_HAS_PTHREAD_SELF
// pthread_t encoded in HEX takes needs as many characters
// as two times the size of the type, plus an additional null byte.
char result[sizeof(pthread_t) * 3 + 10];
apr_snprintf(result, sizeof(result), LOG4CXX_APR_THREAD_FMTSPEC, (void*) &threadId);
- Transcoder::decode(reinterpret_cast<const char*>(result), thread_id_string);
+ thread_id_string = Transcoder::decode(result);
#else
thread_id_string = LOG4CXX_STR("0x00000000");
#endif
@@ -398,11 +398,10 @@ const LogString& LoggingEvent::getCurrentThreadUserName()
#if LOG4CXX_HAS_PTHREAD_GETNAME
char result[16];
pthread_t current_thread = pthread_self();
- if( pthread_getname_np( current_thread, result, sizeof(result) ) < 0 ){
+ if (pthread_getname_np(current_thread, result, sizeof(result)) < 0 || 0 == result[0])
thread_name = LOG4CXX_STR("(noname)");
- }
-
- LOG4CXX_NS::helpers::Transcoder::decode(reinterpret_cast<const char*>(result), thread_name);
+ else
+ thread_name = Transcoder::decode(result);
#elif WIN32
typedef HRESULT (WINAPI *TGetThreadDescription)(HANDLE, PWSTR*);
static struct initialiser
@@ -421,16 +420,16 @@ const LogString& LoggingEvent::getCurrentThreadUserName()
{
PWSTR result = 0;
HRESULT hr = win32func.GetThreadDescription(GetCurrentThread(), &result);
- if (SUCCEEDED(hr))
+ if (SUCCEEDED(hr) && result && *result)
{
std::wstring wresult = result;
LOG4CXX_DECODE_WCHAR(decoded, wresult);
LocalFree(result);
thread_name = decoded;
}
- }else{
- thread_name = LOG4CXX_STR("(noname)");
}
+ if (thread_name.empty())
+ thread_name = LOG4CXX_STR("(noname)");
#else
thread_name = LOG4CXX_STR("(noname)");
#endif