mirror of
https://github.com/warmcat/libwebsockets.git
synced 2025-03-16 00:00:07 +01:00
lwsl stderr sink use formatted time
AG change to use localtime_r for threadsafety and leave old method as fallback
This commit is contained in:
parent
a3f688c189
commit
00919de84e
1 changed files with 16 additions and 4 deletions
|
@ -922,18 +922,30 @@ lws_ensure_user_space(struct lws *wsi)
|
||||||
|
|
||||||
LWS_VISIBLE void lwsl_emit_stderr(int level, const char *line)
|
LWS_VISIBLE void lwsl_emit_stderr(int level, const char *line)
|
||||||
{
|
{
|
||||||
|
time_t o_now = time(NULL);
|
||||||
|
struct tm o_now_time;
|
||||||
unsigned long long now;
|
unsigned long long now;
|
||||||
char buf[300];
|
char buf[300];
|
||||||
int n;
|
int n, ok = localtime_r(&o_now, &o_now_time) != NULL;
|
||||||
|
|
||||||
buf[0] = '\0';
|
buf[0] = '\0';
|
||||||
for (n = 0; n < LLL_COUNT; n++) {
|
for (n = 0; n < LLL_COUNT; n++) {
|
||||||
if (level != (1 << n))
|
if (level != (1 << n))
|
||||||
continue;
|
continue;
|
||||||
now = time_in_microseconds() / 100;
|
now = time_in_microseconds() / 100;
|
||||||
sprintf(buf, "[%llu:%04d] %s: ",
|
if (ok)
|
||||||
(unsigned long long) now / 10000,
|
sprintf(buf, "[%04d/%02d/%02d %02d:%02d:%02d:%04d] %s: ",
|
||||||
(int)(now % 10000), log_level_names[n]);
|
o_now_time.tm_year + 1900,
|
||||||
|
o_now_time.tm_mon,
|
||||||
|
o_now_time.tm_mday,
|
||||||
|
o_now_time.tm_hour,
|
||||||
|
o_now_time.tm_min,
|
||||||
|
o_now_time.tm_sec,
|
||||||
|
(int)(now % 10000), log_level_names[n]);
|
||||||
|
else
|
||||||
|
sprintf(buf, "[%llu:%04d] %s: ",
|
||||||
|
(unsigned long long) now / 10000,
|
||||||
|
(int)(now % 10000), log_level_names[n]);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue