aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/lib/support
diff options
context:
space:
mode:
authorGravatar Craig Tiller <ctiller@google.com>2016-04-21 14:53:14 -0700
committerGravatar Craig Tiller <ctiller@google.com>2016-04-21 14:53:14 -0700
commit39eb886610faf2f17619b9817d17131e5d941c0a (patch)
tree9bb562449cacbb832b1594dfae2f9437b2ed86ed /src/core/lib/support
parent2b3d33ae8a0412076f98a51b4cc2a6cb8c2c3c54 (diff)
parent5a56891eb6b1591e97d36072ac067d762aecf07e (diff)
Merge github.com:grpc/grpc into api_fuzzer
Diffstat (limited to 'src/core/lib/support')
-rw-r--r--src/core/lib/support/log.c33
1 files changed, 33 insertions, 0 deletions
diff --git a/src/core/lib/support/log.c b/src/core/lib/support/log.c
index 04156a5b1f..882abf673c 100644
--- a/src/core/lib/support/log.c
+++ b/src/core/lib/support/log.c
@@ -31,14 +31,20 @@
*
*/
+#include <grpc/support/alloc.h>
+#include <grpc/support/atm.h>
#include <grpc/support/log.h>
#include <grpc/support/port_platform.h>
+#include "src/core/lib/support/env.h"
+#include "src/core/lib/support/string.h"
+
#include <stdio.h>
#include <string.h>
extern void gpr_default_log(gpr_log_func_args *args);
static gpr_log_func g_log_func = gpr_default_log;
+static gpr_atm g_min_severity_to_print = GPR_LOG_VERBOSITY_UNSET;
const char *gpr_log_severity_string(gpr_log_severity severity) {
switch (severity) {
@@ -54,6 +60,9 @@ const char *gpr_log_severity_string(gpr_log_severity severity) {
void gpr_log_message(const char *file, int line, gpr_log_severity severity,
const char *message) {
+ if ((gpr_atm)severity < gpr_atm_no_barrier_load(&g_min_severity_to_print))
+ return;
+
gpr_log_func_args lfargs;
memset(&lfargs, 0, sizeof(lfargs));
lfargs.file = file;
@@ -63,4 +72,28 @@ void gpr_log_message(const char *file, int line, gpr_log_severity severity,
g_log_func(&lfargs);
}
+void gpr_set_log_verbosity(gpr_log_severity min_severity_to_print) {
+ gpr_atm_no_barrier_store(&g_min_severity_to_print,
+ (gpr_atm)min_severity_to_print);
+}
+
+void gpr_log_verbosity_init() {
+ char *verbosity = gpr_getenv("GRPC_VERBOSITY");
+ if (verbosity == NULL) return;
+
+ gpr_atm min_severity_to_print = GPR_LOG_VERBOSITY_UNSET;
+ if (strcmp(verbosity, "DEBUG") == 0) {
+ min_severity_to_print = (gpr_atm)GPR_LOG_SEVERITY_DEBUG;
+ } else if (strcmp(verbosity, "INFO") == 0) {
+ min_severity_to_print = (gpr_atm)GPR_LOG_SEVERITY_INFO;
+ } else if (strcmp(verbosity, "ERROR") == 0) {
+ min_severity_to_print = (gpr_atm)GPR_LOG_SEVERITY_ERROR;
+ }
+ gpr_free(verbosity);
+ if ((gpr_atm_no_barrier_load(&g_min_severity_to_print)) ==
+ GPR_LOG_VERBOSITY_UNSET) {
+ gpr_atm_no_barrier_store(&g_min_severity_to_print, min_severity_to_print);
+ }
+}
+
void gpr_set_log_function(gpr_log_func f) { g_log_func = f; }