Skip to content

Commit

Permalink
wlog: wrong format specifiers, use LWP id on linux
Browse files Browse the repository at this point in the history
  • Loading branch information
nfedera committed Feb 19, 2015
1 parent 970ed7b commit d7243a1
Showing 1 changed file with 26 additions and 11 deletions.
37 changes: 26 additions & 11 deletions winpr/libwinpr/utils/wlog/Layout.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@

#include "wlog/Layout.h"

#if defined __linux__ && !defined ANDROID
#include <unistd.h>
#include <sys/syscall.h>
#endif

extern const char* WLOG_LEVELS[7];

/**
Expand Down Expand Up @@ -126,28 +131,38 @@ void WLog_Layout_GetMessagePrefix(wLog* log, wLogLayout* layout, wLogMessage* me
{
args[argc++] = (void*) (size_t) message->LineNumber;
format[index++] = '%';
format[index++] = 'd';
format[index++] = 'u';
p++;
}
else if ((p[0] == 'p') && (p[1] == 'i') && (p[2] == 'd')) /* process id */
{
args[argc++] = (void*) (size_t) GetCurrentProcessId();
format[index++] = '%';
format[index++] = 'd';
format[index++] = 'u';
p += 2;
}
else if ((p[0] == 't') && (p[1] == 'i') && (p[2] == 'd')) /* thread id */
{
args[argc++] = (void*) (size_t) GetCurrentThreadId();
#if defined __linux__ && !defined ANDROID
/* On Linux we prefer to see the LWP id */
args[argc++] = (void*) (size_t) syscall(SYS_gettid);;
format[index++] = '%';
format[index++] = 'l';
format[index++] = 'd';
#else
args[argc++] = (void*) (size_t) GetCurrentThreadId();
format[index++] = '%';
format[index++] = '0';
format[index++] = '8';
format[index++] = 'x';
#endif
p += 2;
}
else if ((p[0] == 'y') && (p[1] == 'r')) /* year */
{
args[argc++] = (void*) (size_t) localTime.wYear;
format[index++] = '%';
format[index++] = 'd';
format[index++] = 'u';
p++;
}
else if ((p[0] == 'm') && (p[1] == 'o')) /* month */
Expand All @@ -156,7 +171,7 @@ void WLog_Layout_GetMessagePrefix(wLog* log, wLogLayout* layout, wLogMessage* me
format[index++] = '%';
format[index++] = '0';
format[index++] = '2';
format[index++] = 'd';
format[index++] = 'u';
p++;
}
else if ((p[0] == 'd') && (p[1] == 'w')) /* day of week */
Expand All @@ -165,7 +180,7 @@ void WLog_Layout_GetMessagePrefix(wLog* log, wLogLayout* layout, wLogMessage* me
format[index++] = '%';
format[index++] = '0';
format[index++] = '2';
format[index++] = 'd';
format[index++] = 'u';
p++;
}
else if ((p[0] == 'd') && (p[1] == 'y')) /* day */
Expand All @@ -174,7 +189,7 @@ void WLog_Layout_GetMessagePrefix(wLog* log, wLogLayout* layout, wLogMessage* me
format[index++] = '%';
format[index++] = '0';
format[index++] = '2';
format[index++] = 'd';
format[index++] = 'u';
p++;
}
else if ((p[0] == 'h') && (p[1] == 'r')) /* hours */
Expand All @@ -183,7 +198,7 @@ void WLog_Layout_GetMessagePrefix(wLog* log, wLogLayout* layout, wLogMessage* me
format[index++] = '%';
format[index++] = '0';
format[index++] = '2';
format[index++] = 'd';
format[index++] = 'u';
p++;
}
else if ((p[0] == 'm') && (p[1] == 'i')) /* minutes */
Expand All @@ -192,7 +207,7 @@ void WLog_Layout_GetMessagePrefix(wLog* log, wLogLayout* layout, wLogMessage* me
format[index++] = '%';
format[index++] = '0';
format[index++] = '2';
format[index++] = 'd';
format[index++] = 'u';
p++;
}
else if ((p[0] == 's') && (p[1] == 'e')) /* seconds */
Expand All @@ -201,7 +216,7 @@ void WLog_Layout_GetMessagePrefix(wLog* log, wLogLayout* layout, wLogMessage* me
format[index++] = '%';
format[index++] = '0';
format[index++] = '2';
format[index++] = 'd';
format[index++] = 'u';
p++;
}
else if ((p[0] == 'm') && (p[1] == 'l')) /* milliseconds */
Expand All @@ -210,7 +225,7 @@ void WLog_Layout_GetMessagePrefix(wLog* log, wLogLayout* layout, wLogMessage* me
format[index++] = '%';
format[index++] = '0';
format[index++] = '3';
format[index++] = 'd';
format[index++] = 'u';
p++;
}
}
Expand Down

0 comments on commit d7243a1

Please sign in to comment.