summaryrefslogtreecommitdiffstats
path: root/libnetdata/log
diff options
context:
space:
mode:
Diffstat (limited to 'libnetdata/log')
-rw-r--r--libnetdata/log/README.md1
-rw-r--r--libnetdata/log/log.c58
-rw-r--r--libnetdata/log/log.h20
3 files changed, 69 insertions, 10 deletions
diff --git a/libnetdata/log/README.md b/libnetdata/log/README.md
index 3684abd68..f811bb4b3 100644
--- a/libnetdata/log/README.md
+++ b/libnetdata/log/README.md
@@ -12,4 +12,3 @@ learn_rel_path: "Developers/libnetdata"
The netdata log library supports debug, info, error and fatal error logging.
By default we have an access log, an error log and a collectors log.
-
diff --git a/libnetdata/log/log.c b/libnetdata/log/log.c
index e43a4f464..02bb776c5 100644
--- a/libnetdata/log/log.c
+++ b/libnetdata/log/log.c
@@ -12,11 +12,11 @@ int web_server_is_multithreaded = 1;
const char *program_name = "";
uint64_t debug_flags = 0;
-int access_log_syslog = 1;
-int error_log_syslog = 1;
-int collector_log_syslog = 1;
-int output_log_syslog = 1; // debug log
-int health_log_syslog = 1;
+int access_log_syslog = 0;
+int error_log_syslog = 0;
+int collector_log_syslog = 0;
+int output_log_syslog = 0; // debug log
+int health_log_syslog = 0;
int stdaccess_fd = -1;
FILE *stdaccess = NULL;
@@ -34,6 +34,8 @@ const char *facility_log = NULL;
const char *stdhealth_filename = NULL;
const char *stdcollector_filename = NULL;
+netdata_log_level_t global_log_severity_level = NETDATA_LOG_LEVEL_INFO;
+
#ifdef ENABLE_ACLK
const char *aclklog_filename = NULL;
int aclklog_fd = -1;
@@ -780,6 +782,11 @@ void debug_int( const char *file, const char *function, const unsigned long line
void info_int( int is_collector, const char *file __maybe_unused, const char *function __maybe_unused, const unsigned long line __maybe_unused, const char *fmt, ... )
{
+#if !defined(NETDATA_INTERNAL_CHECKS) && !defined(NETDATA_DEV_MODE)
+ if (NETDATA_LOG_LEVEL_INFO > global_log_severity_level)
+ return;
+#endif
+
va_list args;
FILE *fp = (is_collector || !stderror) ? stderr : stderror;
@@ -890,7 +897,7 @@ void error_limit_int(ERROR_LIMIT *erl, const char *prefix, const char *file __ma
erl->count, (unsigned long long)(erl->last_logged ? now - erl->last_logged : 0));
if(erl->sleep_ut)
- fprintf(fp, " (sleeping for %llu microseconds every time this happens)", erl->sleep_ut);
+ fprintf(fp, " (sleeping for %"PRIu64" microseconds every time this happens)", erl->sleep_ut);
if(__errno) {
char buf[1024];
@@ -908,6 +915,11 @@ void error_limit_int(ERROR_LIMIT *erl, const char *prefix, const char *file __ma
}
void error_int(int is_collector, const char *prefix, const char *file __maybe_unused, const char *function __maybe_unused, const unsigned long line __maybe_unused, const char *fmt, ... ) {
+#if !defined(NETDATA_INTERNAL_CHECKS) && !defined(NETDATA_DEV_MODE)
+ if (NETDATA_LOG_LEVEL_ERROR > global_log_severity_level)
+ return;
+#endif
+
// save a copy of errno - just in case this function generates a new error
int __errno = errno;
FILE *fp = (is_collector || !stderror) ? stderr : stderror;
@@ -1125,3 +1137,37 @@ void log_aclk_message_bin( const char *data, const size_t data_len, int tx, cons
}
}
#endif
+
+void log_set_global_severity_level(netdata_log_level_t value)
+{
+ global_log_severity_level = value;
+}
+
+netdata_log_level_t log_severity_string_to_severity_level(char *level)
+{
+ if (!strcmp(level, NETDATA_LOG_LEVEL_INFO_STR))
+ return NETDATA_LOG_LEVEL_INFO;
+ if (!strcmp(level, NETDATA_LOG_LEVEL_ERROR_STR) || !strcmp(level, NETDATA_LOG_LEVEL_ERROR_SHORT_STR))
+ return NETDATA_LOG_LEVEL_ERROR;
+
+ return NETDATA_LOG_LEVEL_INFO;
+}
+
+char *log_severity_level_to_severity_string(netdata_log_level_t level)
+{
+ switch (level) {
+ case NETDATA_LOG_LEVEL_ERROR:
+ return NETDATA_LOG_LEVEL_ERROR_STR;
+ case NETDATA_LOG_LEVEL_INFO:
+ default:
+ return NETDATA_LOG_LEVEL_INFO_STR;
+ }
+}
+
+void log_set_global_severity_for_external_plugins() {
+ char *s = getenv("NETDATA_LOG_SEVERITY_LEVEL");
+ if (!s)
+ return;
+ netdata_log_level_t level = log_severity_string_to_severity_level(s);
+ log_set_global_severity_level(level);
+}
diff --git a/libnetdata/log/log.h b/libnetdata/log/log.h
index 9ced07a9a..cf0865cf9 100644
--- a/libnetdata/log/log.h
+++ b/libnetdata/log/log.h
@@ -43,9 +43,6 @@ extern "C" {
#define D_ANALYTICS 0x0000000080000000
#define D_RRDENGINE 0x0000000100000000
#define D_ACLK 0x0000000200000000
-#define D_METADATALOG 0x0000000400000000
-#define D_ACLK_SYNC 0x0000000800000000
-#define D_META_SYNC 0x0000001000000000
#define D_REPLICATION 0x0000002000000000
#define D_SYSTEM 0x8000000000000000
@@ -105,6 +102,23 @@ typedef struct error_with_limit {
usec_t sleep_ut;
} ERROR_LIMIT;
+typedef enum netdata_log_level {
+ NETDATA_LOG_LEVEL_ERROR,
+ NETDATA_LOG_LEVEL_INFO,
+
+ NETDATA_LOG_LEVEL_END
+} netdata_log_level_t;
+
+#define NETDATA_LOG_LEVEL_INFO_STR "info"
+#define NETDATA_LOG_LEVEL_ERROR_STR "error"
+#define NETDATA_LOG_LEVEL_ERROR_SHORT_STR "err"
+
+extern netdata_log_level_t global_log_severity_level;
+netdata_log_level_t log_severity_string_to_severity_level(char *level);
+char *log_severity_level_to_severity_string(netdata_log_level_t level);
+void log_set_global_severity_level(netdata_log_level_t value);
+void log_set_global_severity_for_external_plugins();
+
#define error_limit_static_global_var(var, log_every_secs, sleep_usecs) static ERROR_LIMIT var = { .last_logged = 0, .count = 0, .log_every = (log_every_secs), .sleep_ut = (sleep_usecs) }
#define error_limit_static_thread_var(var, log_every_secs, sleep_usecs) static __thread ERROR_LIMIT var = { .last_logged = 0, .count = 0, .log_every = (log_every_secs), .sleep_ut = (sleep_usecs) }