Skip to content

Commit

Permalink
core: deprecate __flb_config_verbose and add trace option (fix #52)
Browse files Browse the repository at this point in the history
Signed-off-by: Eduardo Silva <eduardo@treasure-data.com>
  • Loading branch information
edsiper committed Mar 16, 2016
1 parent 26d1692 commit 4f7548b
Show file tree
Hide file tree
Showing 10 changed files with 30 additions and 48 deletions.
8 changes: 1 addition & 7 deletions src/flb_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ struct flb_config *flb_config_init()
{
struct flb_config *config;

__flb_config_verbose = FLB_FALSE;

config = calloc(1, sizeof(struct flb_config));
if (!config) {
perror("malloc");
Expand All @@ -42,6 +40,7 @@ struct flb_config *flb_config_init()
config->flush = FLB_CONFIG_FLUSH_SECS;
config->init_time = time(NULL);
config->kernel = flb_kernel_info();
config->verbose = FLB_FALSE;

mk_list_init(&config->collectors);
mk_list_init(&config->in_plugins);
Expand Down Expand Up @@ -118,8 +117,3 @@ void flb_config_exit(struct flb_config *config)

free(config);
}

void flb_config_verbose(int status)
{
__flb_config_verbose = status;
}
10 changes: 5 additions & 5 deletions src/flb_engine.c
Original file line number Diff line number Diff line change
Expand Up @@ -171,13 +171,13 @@ static inline int flb_engine_manager(int fd, struct flb_config *config)

/* Flush all remaining data */
if (val == FLB_ENGINE_STOP) {
flb_debug("[engine] flush enqueued data");
flb_trace("[engine] flush enqueued data");
flb_engine_flush(config, NULL);
return FLB_ENGINE_STOP;
}
#ifdef HAVE_STATS
else if (val == FLB_ENGINE_STATS) {
flb_debug("[engine] collect stats");
flb_trace("[engine] collect stats");
//flb_stats_collect(config);
return FLB_ENGINE_STATS;
}
Expand Down Expand Up @@ -365,10 +365,10 @@ int flb_engine_start(struct flb_config *config)
event->mask = MK_EVENT_EMPTY;
event->status = MK_EVENT_NONE;
config->shutdown_fd = mk_event_timeout_create(evl, 5, event);
flb_debug("[engine] service will stop in 5 seconds");
flb_warn("[engine] service will stop in 5 seconds");
}
else if (ret == FLB_ENGINE_SHUTDOWN) {
flb_debug("[engine] service stopped");
flb_info("[engine] service stopped");
return flb_engine_shutdown(config);
}
#ifdef HAVE_STATS
Expand All @@ -389,7 +389,7 @@ int flb_engine_start(struct flb_config *config)
th = u->thread;
task = th->task;

flb_debug("[engine] resuming thread: %i", u->event.fd);
flb_trace("[engine] resuming thread: %i", u->event.fd);
flb_thread_resume(th);

if (task->deleted == FLB_TRUE) {
Expand Down
18 changes: 9 additions & 9 deletions src/flb_io.c
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ FLB_INLINE int flb_io_net_connect(struct flb_io_upstream *u,
ret = flb_net_tcp_fd_connect(fd, u->tcp_host, u->tcp_port);
if (ret == -1) {
if (errno == EINPROGRESS) {
flb_debug("[upstream] connection in process");
flb_trace("[upstream] connection in process");
}

MK_EVENT_NEW(&u->event);
Expand Down Expand Up @@ -162,7 +162,7 @@ FLB_INLINE int flb_io_net_connect(struct flb_io_upstream *u,

if (error != 0) {
/* Connection is broken, not much to do here */
flb_debug("[io] connection failed");
flb_trace("[io] connection failed");
return -1;
}

Expand All @@ -173,7 +173,7 @@ FLB_INLINE int flb_io_net_connect(struct flb_io_upstream *u,
}
}

flb_debug("[io] connection OK");
flb_trace("[io] connection OK");
return 0;
}

Expand All @@ -187,15 +187,15 @@ FLB_INLINE int net_io_write(struct flb_thread *th, struct flb_io_upstream *u,

retry:
bytes = write(u->fd, data + total, len - total);
flb_debug("[io] write(2)=%d", bytes);
flb_trace("[io] write(2)=%d", bytes);

if (bytes == -1) {
if (errno == EAGAIN) {
return 0;
}
else {
/* The connection routine may yield */
flb_debug("[io] trying to reconnect");
flb_trace("[io] trying to reconnect");
ret = flb_io_net_connect(u, th);
if (ret == -1) {
return -1;
Expand Down Expand Up @@ -264,7 +264,7 @@ int flb_io_net_write(struct flb_io_upstream *u, void *data,
int ret = -1;
struct flb_thread *th;

flb_debug("[io] trying to write %zd bytes", len);
flb_trace("[io] trying to write %zd bytes", len);

th = pthread_getspecific(flb_thread_key);
if (u->flags & FLB_IO_TCP) {
Expand All @@ -280,7 +280,7 @@ int flb_io_net_write(struct flb_io_upstream *u, void *data,
u->fd = -1;
}

flb_debug("[io] thread has finished");
flb_trace("[io] thread has finished");
return ret;
}

Expand All @@ -289,7 +289,7 @@ ssize_t flb_io_net_read(struct flb_io_upstream *u, void *buf, size_t len)
int ret = -1;
struct flb_thread *th;

flb_debug("[io] trying to read up to %zd bytes", len);
flb_trace("[io] trying to read up to %zd bytes", len);

th = pthread_getspecific(flb_thread_key);
if (u->flags & FLB_IO_TCP) {
Expand All @@ -301,6 +301,6 @@ ssize_t flb_io_net_read(struct flb_io_upstream *u, void *buf, size_t len)
}
#endif

flb_debug("[io] thread has finished");
flb_trace("[io] thread has finished");
return ret;
}
8 changes: 4 additions & 4 deletions src/flb_io_tls.c
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ FLB_INLINE int flb_io_net_tls_connect(struct flb_io_upstream *u,
ret = flb_net_tcp_fd_connect(fd, u->tcp_host, u->tcp_port);
if (ret == -1) {
if (errno == EINPROGRESS) {
flb_debug("[upstream] connection in process");
flb_trace("[upstream] connection in process");
}
else {
close(u->fd);
Expand Down Expand Up @@ -338,13 +338,13 @@ FLB_INLINE int flb_io_net_tls_connect(struct flb_io_upstream *u,
goto retry_handshake;
}
else {
flb_debug("[io_tls] Handshake OK");
flb_trace("[io_tls] Handshake OK");
}

if (u->event.status == MK_EVENT_REGISTERED) {
mk_event_del(u->evl, &u->event);
}
flb_debug("[io_tls] connection OK");
flb_trace("[io_tls] connection OK");
return 0;

error:
Expand Down Expand Up @@ -407,7 +407,7 @@ FLB_INLINE int net_io_tls_write(struct flb_thread *th, struct flb_io_upstream *u
else if (ret < 0) {
char err_buf[72];
mbedtls_strerror(ret, err_buf, sizeof(err_buf));
flb_debug("[tls] SSL error: %s", err_buf);
flb_error("[tls] SSL error: %s", err_buf);

/* There was an error transmitting data */
mk_event_del(u->evl, &u->event);
Expand Down
2 changes: 1 addition & 1 deletion src/flb_kernel.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ struct flb_kernel *flb_kernel_info()
kernel->s_version.len = len;
kernel->n_version = FLB_KERNEL_VERSION(a, b, c);

flb_debug("Linux Kernel = %i.%i.%i", a, b, c);
flb_trace("Linux Kernel = %i.%i.%i", a, b, c);

return kernel;
}
6 changes: 3 additions & 3 deletions src/flb_lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ int flb_start(flb_ctx_t *ctx)
}

if (val == FLB_ENGINE_STARTED) {
flb_debug("[lib] backend started");
flb_debug(config, "[lib] backend started");
break;
}
}
Expand All @@ -239,11 +239,11 @@ int flb_stop(flb_ctx_t *ctx)
mk_rconf_free(ctx->config->file);
}

flb_debug("[lib] sending STOP signal to the engine");
flb_debug(ctx->config, "[lib] sending STOP signal to the engine");
val = FLB_ENGINE_STOP;
write(ctx->config->ch_manager[1], &val, sizeof(uint64_t));
ret = pthread_join(ctx->config->worker, NULL);

flb_debug("[lib] Fluent Bit engine stopped");
flb_debug(ctx->config, "[lib] Fluent Bit engine stopped");
return ret;
}
10 changes: 5 additions & 5 deletions src/flb_network.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,11 @@ int flb_net_host_set(char *plugin_name, struct flb_net_host *host, char *address
u = strchr(s, '/');
if (u) {
host->uri = flb_uri_create(u);
if (__flb_config_verbose == FLB_TRUE) {
flb_debug("[URI dump] entries=%i '%s'",
host->uri->count, u);
flb_uri_dump(host->uri);
}
#ifdef FLB_TRACE
flb_trace("[URI dump] entries=%i '%s'",
host->uri->count, u);
flb_uri_dump(host->uri);
#endif
}
host->address = strdup(address);

Expand Down
2 changes: 1 addition & 1 deletion src/flb_pack.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ static int json_tokenise(char *js, size_t len,

if (ret == JSMN_ERROR_PART) {
/* This is a partial JSON message, just stop */
flb_debug("[json tokenise] incomplete");
flb_trace("[json tokenise] incomplete");
return FLB_ERR_JSON_PART;
}

Expand Down
12 changes: 0 additions & 12 deletions src/flb_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,6 @@ void flb_utils_warn_c(const char *msg)
ANSI_BOLD ANSI_YELLOW, ANSI_RESET, msg);
}

int flb_debug_enabled()
{
return __flb_config_verbose;

}

void flb_message(int type, const char *fmt, ...)
{
time_t now;
Expand All @@ -131,12 +125,6 @@ void flb_message(int type, const char *fmt, ...)
const char *reset_color = ANSI_RESET;
va_list args;

if (type == FLB_MSG_DEBUG) {
if (__flb_config_verbose == FLB_FALSE) {
return;
}
}

va_start(args, fmt);

switch (type) {
Expand Down
2 changes: 1 addition & 1 deletion src/fluent-bit.c
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ int main(int argc, char **argv)
flb_version();
exit(EXIT_SUCCESS);
case 'V':
config->verbose = __flb_config_verbose = FLB_TRUE;
config->verbose = FLB_TRUE;
break;
default:
flb_help(EXIT_FAILURE, config);
Expand Down

0 comments on commit 4f7548b

Please sign in to comment.