Skip to content

Commit d250bfd

Browse files
committed
improve logs
Change-Id: I487f1720ca137a5104ec85ba8d8aaec5aae05d3b Reviewed-on: https://review.couchbase.org/c/libcouchbase/+/197288 Reviewed-by: Brett Lawson <brett19@gmail.com> Tested-by: Build Bot <build@couchbase.com>
1 parent 25637cf commit d250bfd

15 files changed

Lines changed: 54 additions & 30 deletions

File tree

contrib/cbsasl/src/cram-md5/md5.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@
2828
#elif !defined(_MD5_H)
2929
#define _MD5_H
3030

31+
#ifdef __cplusplus
32+
extern "C" {
33+
#endif
34+
3135
/* Any 32-bit or wider unsigned integer data type will do */
3236
typedef unsigned int MD5_u32plus;
3337

@@ -42,4 +46,8 @@ extern void cbsasl_MD5_Init(MD5_CTX *ctx);
4246
extern void cbsasl_MD5_Update(MD5_CTX *ctx, void *data, unsigned long size);
4347
extern void cbsasl_MD5_Final(unsigned char *result, MD5_CTX *ctx);
4448

49+
#ifdef __cplusplus
50+
}
51+
#endif
52+
4553
#endif

contrib/cbsasl/src/util.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@
1818
#define CBSASL_UTIL_H_ 1
1919
#include <config.h>
2020

21+
#ifdef __cplusplus
22+
extern "C" {
23+
#endif
24+
2125
/* Encode hexadecimal representation of bytes from src into dest.
2226
* Will write srclen * 2 bytes. */
2327
void cbsasl_hex_encode(char *dest, const char *src, size_t srclen);
@@ -27,5 +31,8 @@ int cbsasl_secure_compare(const char *a, size_t alen, const char *b, size_t blen
2731

2832
cbsasl_error_t cbsasl_secure_random(char *dest, size_t len);
2933

34+
#ifdef __cplusplus
35+
}
36+
#endif
3037

3138
#endif /* CBSASL_UTIL_H_ */

example/db/dbx.cc

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,13 +129,20 @@ static void get_callback(lcb_INSTANCE *instance, int, const lcb_RESPGET *resp)
129129

130130
rc = lcb_respget_status(resp);
131131
if (rc != LCB_SUCCESS) {
132+
const lcb_KEY_VALUE_ERROR_CONTEXT *ctx{};
133+
lcb_respget_error_context(resp, &ctx);
134+
const char *endpoint{};
135+
size_t endpoint_length{};
136+
if (ctx != nullptr) {
137+
lcb_errctx_kv_endpoint(ctx, &endpoint, &endpoint_length);
138+
}
132139
if (rc == LCB_ERR_DOCUMENT_NOT_FOUND) {
133140
std::cerr << "unable to get \"" << std::string(key, key_len) << "\". rc: " << lcb_strerror_short(rc)
134-
<< ". Creating new document\n";
141+
<< ", endpoint: " << std::string(endpoint, endpoint_length) << ". Creating new document\n";
135142
upsert_key(instance, key, key_len);
136143
} else {
137144
std::cerr << "unable to get \"" << std::string(key, key_len) << "\". rc: " << lcb_strerror_short(rc)
138-
<< "\n";
145+
<< ", endpoint: " << std::string(endpoint, endpoint_length) << "\n";
139146
}
140147
}
141148

src/bucketconfig/bc_cccp.cc

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -202,9 +202,9 @@ lcb_STATUS CccpProvider::expect_config_with_version(const lcb_host_t *origin, co
202202
*/
203203
lcb_log(LOGARGS(this, TRACE),
204204
"Ignore configuration request " LCB_HOST_FMT ": expected=%" PRId64 ":%" PRId64 ", current=%" PRId64
205-
":%" PRId64 ", requested=%" PRId64 ":%" PRId64,
205+
":%" PRId64 ", requested=%" PRId64 ":%" PRId64 ", has_pending_request=%d",
206206
LCB_HOST_ARG(parent->settings, origin), previous_expected.epoch, previous_expected.revision,
207-
current.epoch, current.revision, requested.epoch, requested.revision);
207+
current.epoch, current.revision, requested.epoch, requested.revision, has_pending_request());
208208
}
209209
return LCB_SUCCESS;
210210
}
@@ -423,8 +423,7 @@ static void on_connected(lcbio_SOCKET *sock, void *data, lcb_STATUS err, lcbio_O
423423

424424
ioprocs.cb_err = io_error_handler;
425425
ioprocs.cb_read = io_read_handler;
426-
cccp->ioctx = lcbio_ctx_new(sock, data, &ioprocs);
427-
cccp->ioctx->subsys = "bc_cccp";
426+
cccp->ioctx = lcbio_ctx_new(sock, data, &ioprocs, "bc_cccp");
428427
sock->service = LCBIO_SERVICE_CFG;
429428
cccp->request_config();
430429
}

src/bucketconfig/bc_http.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -326,8 +326,7 @@ static void on_connected(lcbio_SOCKET *sock, void *arg, lcb_STATUS err, lcbio_OS
326326

327327
procs.cb_err = io_error_handler;
328328
procs.cb_read = read_common;
329-
http->ioctx = lcbio_ctx_new(sock, http, &procs);
330-
http->ioctx->subsys = "bc_http";
329+
http->ioctx = lcbio_ctx_new(sock, http, &procs, "bc_http");
331330
sock->service = LCBIO_SERVICE_CFG;
332331

333332
lcbio_ctx_put(http->ioctx, http->request_buf.c_str(), http->request_buf.size());

src/http/http_io.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -253,9 +253,8 @@ static void on_connected(lcbio_SOCKET *sock, void *arg, lcb_STATUS err, lcbio_OS
253253

254254
procs.cb_err = io_error;
255255
procs.cb_read = io_read;
256-
req->ioctx = lcbio_ctx_new(sock, arg, &procs);
256+
req->ioctx = lcbio_ctx_new(sock, arg, &procs, "mgmt/capi");
257257
sock->service = service;
258-
req->ioctx->subsys = "mgmt/capi";
259258
lcbio_ctx_put(req->ioctx, &req->preamble[0], req->preamble.size());
260259
if (!req->body.empty()) {
261260
lcbio_ctx_put(req->ioctx, &req->body[0], req->body.size());

src/lcbio/connect.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,9 @@ void Connstart::state_signal(State next_state, lcb_STATUS err)
203203
} else if (last_error == LCB_SUCCESS) {
204204
/* set error code only if previous code was not a failure */
205205
last_error = err;
206+
} else {
207+
lcb_log(LOGARGS_T(DEBUG), CSLOGFMT "Do not override last_error. current: %s, new: %s", CSLOGID_T(),
208+
lcb_strerror_short(last_error), lcb_strerror_short(err));
206209
}
207210

208211
state = next_state;

src/lcbio/ctx.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ static lcb_STATUS convert_lcberr(const lcbio_CTX *ctx, lcbio_IOSTATUS status)
6464
}
6565
}
6666

67-
lcbio_CTX *lcbio_ctx_new(lcbio_SOCKET *sock, void *data, const lcbio_CTXPROCS *procs)
67+
lcbio_CTX *lcbio_ctx_new(lcbio_SOCKET *sock, void *data, const lcbio_CTXPROCS *procs, const char *subsys)
6868
{
6969
auto *ctx = new lcbio_CTX{};
7070
ctx->sock = sock;
@@ -74,7 +74,7 @@ lcbio_CTX *lcbio_ctx_new(lcbio_SOCKET *sock, void *data, const lcbio_CTXPROCS *p
7474
ctx->procs = *procs;
7575
ctx->state = ES_ACTIVE;
7676
ctx->as_err = lcbio_timer_new(ctx->io, ctx, err_handler);
77-
ctx->subsys = "unknown";
77+
ctx->subsys = subsys == nullptr ? "unknown" : subsys;
7878
sock->service = LCBIO_SERVICE_UNSPEC;
7979
sock->atime = LCB_NS2US(gethrtime());
8080

@@ -361,7 +361,7 @@ static void Cr_handler(lcb_sockdata_t *sd, lcb_ssize_t nr, void *arg)
361361
{
362362
char *b64 = nullptr;
363363
lcb_SIZE nb64 = 0;
364-
char *buf = calloc(total, sizeof(char));
364+
char *buf = (char *)calloc(total, sizeof(char));
365365
rdb_copyread(&ctx->ior, buf, total);
366366
lcb_base64_encode2(buf, total, &b64, &nb64);
367367
lcb_log(LOGARGS(ctx, TRACE), CTX_LOGFMT "pkt,rcv: size=%d, %.*s", CTX_LOGID(ctx), (int)nb64,

src/lcbio/ctx.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ typedef struct lcbio_CTX {
167167
* @param procs callback table
168168
* @return a new context object.
169169
*/
170-
lcbio_CTX *lcbio_ctx_new(lcbio_SOCKET *sock, void *data, const lcbio_CTXPROCS *procs);
170+
lcbio_CTX *lcbio_ctx_new(lcbio_SOCKET *sock, void *data, const lcbio_CTXPROCS *procs, const char *subsys);
171171

172172
/**
173173
* Callback invoked when the connection is about to be release

src/lcbio/manager.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -326,8 +326,8 @@ void PoolRequest::invoke()
326326
PoolConnInfo *info = PoolConnInfo::from_sock(sock);
327327
info->set_leased();
328328
state = ASSIGNED;
329-
lcb_log(LOGARGS(info->parent->parent, DEBUG), HE_LOGFMT "Assigning R=%p SOCKET=%p", HE_LOGID(info->parent),
330-
(void *)this, (void *)sock);
329+
lcb_log(LOGARGS(info->parent->parent, DEBUG), HE_LOGFMT "Assigning R=%p SOCKET=%p, SOCK=%016" PRIx64,
330+
HE_LOGID(info->parent), (void *)this, (void *)sock, sock->id);
331331
}
332332

333333
callback(sock, arg, err, 0);

0 commit comments

Comments
 (0)