master
c 105 lines 4.39 KB
Raw
1 // SPDX-License-Identifier: GPL-3.0-or-later
2
3 #include "netdata-conf-logs.h"
4 #include "daemon/common.h"
5
6 static void debug_flags_initialize(void) {
7 // --------------------------------------------------------------------
8 // get the debugging flags from the configuration file
9
10 const char *flags = inicfg_get(&netdata_config, CONFIG_SECTION_LOGS, "debug flags", "0x0000000000000000");
11 nd_setenv("NETDATA_DEBUG_FLAGS", flags, 1);
12
13 debug_flags = strtoull(flags, NULL, 0);
14 netdata_log_debug(D_OPTIONS, "Debug flags set to '0x%" PRIX64 "'.", debug_flags);
15
16 if(debug_flags != 0) {
17 struct rlimit rl = { RLIM_INFINITY, RLIM_INFINITY };
18 if(setrlimit(RLIMIT_CORE, &rl) != 0)
19 netdata_log_error("Cannot request unlimited core dumps for debugging... Proceeding anyway...");
20
21 #ifdef HAVE_SYS_PRCTL_H
22 prctl(PR_SET_DUMPABLE, 1, 0, 0, 0);
23 #endif
24 }
25 }
26
27 void netdata_conf_section_logs(void) {
28 FUNCTION_RUN_ONCE();
29
30 netdata_conf_section_directories();
31
32 nd_log_set_facility(inicfg_get(&netdata_config, CONFIG_SECTION_LOGS, "facility", "daemon"));
33
34 time_t period = ND_LOG_DEFAULT_THROTTLE_PERIOD;
35 size_t logs = ND_LOG_DEFAULT_THROTTLE_LOGS;
36 period = inicfg_get_duration_seconds(&netdata_config, CONFIG_SECTION_LOGS, "logs flood protection period", period);
37 logs = (unsigned long)inicfg_get_number(&netdata_config, CONFIG_SECTION_LOGS, "logs to trigger flood protection", (long long int)logs);
38 nd_log_set_flood_protection(logs, period);
39
40 const char *netdata_log_level = getenv("NETDATA_LOG_LEVEL");
41 netdata_log_level = netdata_log_level ? nd_log_id2priority(nd_log_priority2id(netdata_log_level)) : NDLP_INFO_STR;
42
43 nd_log_set_priority_level(inicfg_get(&netdata_config, CONFIG_SECTION_LOGS, "level", netdata_log_level));
44
45 char filename[FILENAME_MAX + 1];
46 char* os_default_method = NULL;
47 #if defined(OS_LINUX)
48 os_default_method = is_stderr_connected_to_journal() /* || nd_log_journal_socket_available() */ ? "journal" : NULL;
49 #elif defined(OS_WINDOWS)
50 #if defined(HAVE_ETW)
51 os_default_method = "etw";
52 #elif defined(HAVE_WEL)
53 os_default_method = "wel";
54 #endif
55 #endif
56
57 #if defined(OS_WINDOWS)
58 // on windows, debug log goes to windows events
59 snprintfz(filename, FILENAME_MAX, "%s", os_default_method);
60 #else
61 snprintfz(filename, FILENAME_MAX, "%s/debug.log", netdata_configured_log_dir);
62 #endif
63
64 nd_log_set_user_settings(NDLS_DEBUG, inicfg_get_log_path_setting(&netdata_config, CONFIG_SECTION_LOGS, "debug", filename));
65
66 if(os_default_method)
67 snprintfz(filename, FILENAME_MAX, "%s", os_default_method);
68 else
69 snprintfz(filename, FILENAME_MAX, "%s/daemon.log", netdata_configured_log_dir);
70 nd_log_set_user_settings(NDLS_DAEMON, inicfg_get_log_path_setting(&netdata_config, CONFIG_SECTION_LOGS, "daemon", filename));
71
72 if(os_default_method)
73 snprintfz(filename, FILENAME_MAX, "%s", os_default_method);
74 else
75 snprintfz(filename, FILENAME_MAX, "%s/collector.log", netdata_configured_log_dir);
76 nd_log_set_user_settings(NDLS_COLLECTORS, inicfg_get_log_path_setting(&netdata_config, CONFIG_SECTION_LOGS, "collector", filename));
77
78 #if defined(OS_WINDOWS)
79 // on windows, access log goes to windows events
80 snprintfz(filename, FILENAME_MAX, "%s", os_default_method);
81 #else
82 snprintfz(filename, FILENAME_MAX, "%s/access.log", netdata_configured_log_dir);
83 #endif
84 nd_log_set_user_settings(NDLS_ACCESS, inicfg_get_log_path_setting(&netdata_config, CONFIG_SECTION_LOGS, "access", filename));
85
86 if(os_default_method)
87 snprintfz(filename, FILENAME_MAX, "%s", os_default_method);
88 else
89 snprintfz(filename, FILENAME_MAX, "%s/health.log", netdata_configured_log_dir);
90 nd_log_set_user_settings(NDLS_HEALTH, inicfg_get_log_path_setting(&netdata_config, CONFIG_SECTION_LOGS, "health", filename));
91
92 aclklog_enabled = inicfg_get_boolean(&netdata_config, CONFIG_SECTION_CLOUD, "conversation log", CONFIG_BOOLEAN_NO);
93 if (aclklog_enabled) {
94 #if defined(OS_WINDOWS)
95 // on windows, aclk log goes to windows events
96 snprintfz(filename, FILENAME_MAX, "%s", os_default_method);
97 #else
98 snprintfz(filename, FILENAME_MAX, "%s/aclk.log", netdata_configured_log_dir);
99 #endif
100 nd_log_set_user_settings(NDLS_ACLK, inicfg_get_log_path_setting(&netdata_config, CONFIG_SECTION_CLOUD, "conversation log file", filename));
101 }
102
103 debug_flags_initialize();
104 aclk_config_get_query_scope();
105 }