Libunit: improving logging consistency.

Debug logging depends on macros defined in nxt_auto_config.h.
This commit is contained in:
Max Romanov
2020-11-18 22:33:53 +03:00
parent fb80502513
commit 8340ca0b9c
5 changed files with 11 additions and 6 deletions

View File

@@ -379,6 +379,7 @@ libunit-install: $NXT_BUILD_DIR/$NXT_LIB_UNIT_STATIC
src/nxt_unit_sptr.h \ src/nxt_unit_sptr.h \
src/nxt_unit_typedefs.h \ src/nxt_unit_typedefs.h \
src/nxt_unit_websocket.h \ src/nxt_unit_websocket.h \
$NXT_BUILD_DIR/nxt_auto_config.h \
$NXT_BUILD_DIR/nxt_version.h \ $NXT_BUILD_DIR/nxt_version.h \
src/nxt_websocket_header.h \ src/nxt_websocket_header.h \
\$(DESTDIR)$NXT_INCDIR/ \$(DESTDIR)$NXT_INCDIR/
@@ -393,6 +394,7 @@ libunit-uninstall:
\$(DESTDIR)$NXT_INCDIR/nxt_unit_sptr.h \ \$(DESTDIR)$NXT_INCDIR/nxt_unit_sptr.h \
\$(DESTDIR)$NXT_INCDIR/nxt_unit_typedefs.h \ \$(DESTDIR)$NXT_INCDIR/nxt_unit_typedefs.h \
\$(DESTDIR)$NXT_INCDIR/nxt_unit_websocket.h \ \$(DESTDIR)$NXT_INCDIR/nxt_unit_websocket.h \
\$(DESTDIR)$NXT_INCDIR/nxt_auto_config.h \
\$(DESTDIR)$NXT_INCDIR/nxt_version.h \ \$(DESTDIR)$NXT_INCDIR/nxt_version.h \
\$(DESTDIR)$NXT_INCDIR/nxt_websocket_header.h \$(DESTDIR)$NXT_INCDIR/nxt_websocket_header.h
@rmdir -p \$(DESTDIR)$NXT_INCDIR 2>/dev/null || true @rmdir -p \$(DESTDIR)$NXT_INCDIR 2>/dev/null || true

View File

@@ -6527,7 +6527,9 @@ nxt_unit_malloc(nxt_unit_ctx_t *ctx, size_t size)
p = malloc(size); p = malloc(size);
if (nxt_fast_path(p != NULL)) { if (nxt_fast_path(p != NULL)) {
#if (NXT_DEBUG_ALLOC)
nxt_unit_debug(ctx, "malloc(%d): %p", (int) size, p); nxt_unit_debug(ctx, "malloc(%d): %p", (int) size, p);
#endif
} else { } else {
nxt_unit_alert(ctx, "malloc(%d) failed: %s (%d)", nxt_unit_alert(ctx, "malloc(%d) failed: %s (%d)",
@@ -6541,7 +6543,9 @@ nxt_unit_malloc(nxt_unit_ctx_t *ctx, size_t size)
void void
nxt_unit_free(nxt_unit_ctx_t *ctx, void *p) nxt_unit_free(nxt_unit_ctx_t *ctx, void *p)
{ {
#if (NXT_DEBUG_ALLOC)
nxt_unit_debug(ctx, "free(%p)", p); nxt_unit_debug(ctx, "free(%p)", p);
#endif
free(p); free(p);
} }

View File

@@ -12,6 +12,7 @@
#include <sys/uio.h> #include <sys/uio.h>
#include <string.h> #include <string.h>
#include "nxt_auto_config.h"
#include "nxt_version.h" #include "nxt_version.h"
#include "nxt_unit_typedefs.h" #include "nxt_unit_typedefs.h"

View File

@@ -3,8 +3,6 @@
* Copyright (C) NGINX, Inc. * Copyright (C) NGINX, Inc.
*/ */
#include <nxt_auto_config.h>
#include <nxt_version.h>
#include <nxt_unit.h> #include <nxt_unit.h>
#include <nxt_unit_request.h> #include <nxt_unit_request.h>
#include <nxt_clang.h> #include <nxt_clang.h>

View File

@@ -30,7 +30,7 @@ typedef struct {
static int ws_chat_root(nxt_unit_request_info_t *req); static int ws_chat_root(nxt_unit_request_info_t *req);
static void ws_chat_broadcast(const void *buf, size_t size); static void ws_chat_broadcast(const char *buf, size_t size);
static const char ws_chat_index_html[]; static const char ws_chat_index_html[];
@@ -139,18 +139,18 @@ ws_chat_root(nxt_unit_request_info_t *req)
static void static void
ws_chat_broadcast(const void *buf, size_t size) ws_chat_broadcast(const char *buf, size_t size)
{ {
ws_chat_request_data_t *data; ws_chat_request_data_t *data;
nxt_unit_request_info_t *req; nxt_unit_request_info_t *req;
nxt_unit_debug(NULL, "broadcast: %s", buf); nxt_unit_debug(NULL, "broadcast: %*.s", (int) size, buf);
nxt_queue_each(data, &ws_chat_sessions, ws_chat_request_data_t, link) { nxt_queue_each(data, &ws_chat_sessions, ws_chat_request_data_t, link) {
req = nxt_unit_get_request_info_from_data(data); req = nxt_unit_get_request_info_from_data(data);
nxt_unit_req_debug(req, "broadcast: %s", buf); nxt_unit_req_debug(req, "send: %*.s", (int) size, buf);
nxt_unit_websocket_send(req, NXT_WEBSOCKET_OP_TEXT, 1, buf, size); nxt_unit_websocket_send(req, NXT_WEBSOCKET_OP_TEXT, 1, buf, size);
} nxt_queue_loop; } nxt_queue_loop;