Skip to content

Commit

Permalink
ccommon: pelikan - add stats for memcache klog
Browse files Browse the repository at this point in the history
RB_ID=750660
  • Loading branch information
kevyang committed Oct 4, 2015
1 parent d1fdbf3 commit 4a96b0e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 16 deletions.
4 changes: 3 additions & 1 deletion include/cc_log.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,9 @@ void log_destroy(struct logger **logger);

rstatus_t log_reopen(struct logger *logger);

void _log_write(struct logger *logger, char *buf, int len);
/* _log_write returns true if msg written, false if skipped or failed */
bool _log_write(struct logger *logger, char *buf, int len);

void _log_fd(int fd, const char *fmt, ...);

void log_flush(struct logger *logger);
Expand Down
30 changes: 15 additions & 15 deletions src/cc_log.c
Original file line number Diff line number Diff line change
Expand Up @@ -162,36 +162,36 @@ log_reopen(struct logger *logger)
return CC_OK;
}

void
bool
_log_write(struct logger *logger, char *buf, int len)
{
int n;

if (logger->buf != NULL) {
n = rbuf_write(logger->buf, buf, len);
if (rbuf_wcap(logger->buf) >= len) {
rbuf_write(logger->buf, buf, len);
INCR(log_metrics, log_write);
INCR_N(log_metrics, log_write_byte, len);
} else {
INCR(log_metrics, log_skip);
INCR_N(log_metrics, log_skip_byte, len);
return false;
}
} else {
if (logger->fd < 0) {
INCR(log_metrics, log_write_ex);
return;
return false;
}

n = write(logger->fd, buf, len);

if (n < 0) {
if (write(logger->fd, buf, len) < len) {
INCR(log_metrics, log_write_ex);
logger->nerror++;
return;
return false;
}
}

if (n < len) {
INCR(log_metrics, log_skip);
INCR_N(log_metrics, log_skip_byte, len - n);
logger->nerror++;
} else {
INCR(log_metrics, log_write);
INCR_N(log_metrics, log_write_byte, len);
}

return true;
}

void
Expand Down

0 comments on commit 4a96b0e

Please sign in to comment.