fixed a bug in the default log callback
This commit is contained in:
parent
46ff9acfe2
commit
11dbde8380
@ -994,7 +994,7 @@ static void fini_hcl (hcl_t* hcl)
|
|||||||
/* ========================================================================= */
|
/* ========================================================================= */
|
||||||
|
|
||||||
|
|
||||||
#undef char_t
|
#undef ooch_t
|
||||||
#undef oocs_t
|
#undef oocs_t
|
||||||
#undef str_to_ipv4
|
#undef str_to_ipv4
|
||||||
#undef str_to_ipv6
|
#undef str_to_ipv6
|
||||||
|
@ -150,7 +150,7 @@ static int write_log (hcl_server_t* server, int fd, const hcl_bch_t* ptr, hcl_oo
|
|||||||
|
|
||||||
if (xtn->logbuf.len >= HCL_COUNTOF(xtn->logbuf.buf))
|
if (xtn->logbuf.len >= HCL_COUNTOF(xtn->logbuf.buf))
|
||||||
{
|
{
|
||||||
write_all(xtn->logfd, xtn->logbuf.buf, xtn->logbuf.len);
|
write_all(fd, xtn->logbuf.buf, xtn->logbuf.len);
|
||||||
xtn->logbuf.len = 0;
|
xtn->logbuf.len = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -251,7 +251,7 @@ static void log_write (hcl_server_t* server, hcl_oow_t wid, unsigned int mask, c
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (xtn->logfd_istty)
|
if (logfd == xtn->logfd && xtn->logfd_istty)
|
||||||
{
|
{
|
||||||
if (mask & HCL_LOG_FATAL) write_log (server, logfd, "\x1B[1;31m", 7);
|
if (mask & HCL_LOG_FATAL) write_log (server, logfd, "\x1B[1;31m", 7);
|
||||||
else if (mask & HCL_LOG_ERROR) write_log (server, logfd, "\x1B[1;32m", 7);
|
else if (mask & HCL_LOG_ERROR) write_log (server, logfd, "\x1B[1;32m", 7);
|
||||||
@ -297,7 +297,7 @@ static void log_write (hcl_server_t* server, hcl_oow_t wid, unsigned int mask, c
|
|||||||
write_log (server, logfd, msg, len);
|
write_log (server, logfd, msg, len);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (xtn->logfd_istty)
|
if (logfd == xtn->logfd && xtn->logfd_istty)
|
||||||
{
|
{
|
||||||
if (mask & (HCL_LOG_FATAL | HCL_LOG_ERROR | HCL_LOG_WARN)) write_log (server, logfd, "\x1B[0m", 4);
|
if (mask & (HCL_LOG_FATAL | HCL_LOG_ERROR | HCL_LOG_WARN)) write_log (server, logfd, "\x1B[0m", 4);
|
||||||
}
|
}
|
||||||
|
30
lib/main.c
30
lib/main.c
@ -552,7 +552,7 @@ static int write_all (int fd, const hcl_bch_t* ptr, hcl_oow_t len)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int write_log (hcl_t* hcl, const hcl_bch_t* ptr, hcl_oow_t len)
|
static int write_log (hcl_t* hcl, int fd, const hcl_bch_t* ptr, hcl_oow_t len)
|
||||||
{
|
{
|
||||||
xtn_t* xtn;
|
xtn_t* xtn;
|
||||||
|
|
||||||
@ -575,7 +575,7 @@ static int write_log (hcl_t* hcl, const hcl_bch_t* ptr, hcl_oow_t len)
|
|||||||
if (xtn->logbuf.len >= HCL_COUNTOF(xtn->logbuf.buf))
|
if (xtn->logbuf.len >= HCL_COUNTOF(xtn->logbuf.buf))
|
||||||
{
|
{
|
||||||
int n;
|
int n;
|
||||||
n = write_all(xtn->logfd, xtn->logbuf.buf, xtn->logbuf.len);
|
n = write_all(fd, xtn->logbuf.buf, xtn->logbuf.len);
|
||||||
xtn->logbuf.len = 0;
|
xtn->logbuf.len = 0;
|
||||||
if (n <= -1) return -1;
|
if (n <= -1) return -1;
|
||||||
}
|
}
|
||||||
@ -587,7 +587,7 @@ static int write_log (hcl_t* hcl, const hcl_bch_t* ptr, hcl_oow_t len)
|
|||||||
rcapa = HCL_COUNTOF(xtn->logbuf.buf);
|
rcapa = HCL_COUNTOF(xtn->logbuf.buf);
|
||||||
if (len >= rcapa)
|
if (len >= rcapa)
|
||||||
{
|
{
|
||||||
if (write_all(xtn->logfd, ptr, rcapa) <= -1) return -1;
|
if (write_all(fd, ptr, rcapa) <= -1) return -1;
|
||||||
ptr += rcapa;
|
ptr += rcapa;
|
||||||
len -= rcapa;
|
len -= rcapa;
|
||||||
}
|
}
|
||||||
@ -605,13 +605,13 @@ static int write_log (hcl_t* hcl, const hcl_bch_t* ptr, hcl_oow_t len)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void flush_log (hcl_t* hcl)
|
static void flush_log (hcl_t* hcl, int fd)
|
||||||
{
|
{
|
||||||
xtn_t* xtn;
|
xtn_t* xtn;
|
||||||
xtn = hcl_getxtn(hcl);
|
xtn = hcl_getxtn(hcl);
|
||||||
if (xtn->logbuf.len > 0)
|
if (xtn->logbuf.len > 0)
|
||||||
{
|
{
|
||||||
write_all (xtn->logfd, xtn->logbuf.buf, xtn->logbuf.len);
|
write_all (fd, xtn->logbuf.buf, xtn->logbuf.len);
|
||||||
xtn->logbuf.len = 0;
|
xtn->logbuf.len = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -675,14 +675,14 @@ static void log_write (hcl_t* hcl, unsigned int mask, const hcl_ooch_t* msg, hcl
|
|||||||
tslen = 25;
|
tslen = 25;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
write_log (hcl, ts, tslen);
|
write_log (hcl, logfd, ts, tslen);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (xtn->logfd_istty)
|
if (logfd == xtn->logfd && xtn->logfd_istty)
|
||||||
{
|
{
|
||||||
if (mask & HCL_LOG_FATAL) write_log (hcl, "\x1B[1;31m", 7);
|
if (mask & HCL_LOG_FATAL) write_log (hcl, logfd, "\x1B[1;31m", 7);
|
||||||
else if (mask & HCL_LOG_ERROR) write_log (hcl, "\x1B[1;32m", 7);
|
else if (mask & HCL_LOG_ERROR) write_log (hcl, logfd, "\x1B[1;32m", 7);
|
||||||
else if (mask & HCL_LOG_WARN) write_log (hcl, "\x1B[1;33m", 7);
|
else if (mask & HCL_LOG_WARN) write_log (hcl, logfd, "\x1B[1;33m", 7);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(HCL_OOCH_IS_UCH)
|
#if defined(HCL_OOCH_IS_UCH)
|
||||||
@ -704,7 +704,7 @@ static void log_write (hcl_t* hcl, unsigned int mask, const hcl_ooch_t* msg, hcl
|
|||||||
HCL_ASSERT (hcl, ucslen > 0); /* if this fails, the buffer size must be increased */
|
HCL_ASSERT (hcl, ucslen > 0); /* if this fails, the buffer size must be increased */
|
||||||
|
|
||||||
/* attempt to write all converted characters */
|
/* attempt to write all converted characters */
|
||||||
if (write_log (hcl, buf, bcslen) <= -1) break;
|
if (write_log(hcl, logfd, buf, bcslen) <= -1) break;
|
||||||
|
|
||||||
if (n == 0) break;
|
if (n == 0) break;
|
||||||
else
|
else
|
||||||
@ -720,15 +720,15 @@ static void log_write (hcl_t* hcl, unsigned int mask, const hcl_ooch_t* msg, hcl
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
write_log (hcl, msg, len);
|
write_log (hcl, logfd, msg, len);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (xtn->logfd_istty)
|
if (logfd == xtn->logfd && xtn->logfd_istty)
|
||||||
{
|
{
|
||||||
if (mask & (HCL_LOG_FATAL | HCL_LOG_ERROR | HCL_LOG_WARN)) write_log (hcl, "\x1B[0m", 4);
|
if (mask & (HCL_LOG_FATAL | HCL_LOG_ERROR | HCL_LOG_WARN)) write_log (hcl, logfd, "\x1B[0m", 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
flush_log (hcl);
|
flush_log (hcl, logfd);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user