2 CTDB logging config handling
4 Copyright (C) Martin Schwenke 2017
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, see <http://www.gnu.org/licenses/>.
24 #include "common/conf.h"
25 #include "common/logging.h"
26 #include "common/logging_conf.h"
28 #define LOGGING_LOCATION_DEFAULT "file:" LOGDIR "/log.ctdb"
29 #define LOGGING_LOG_LEVEL_DEFAULT "ERROR"
31 static bool logging_conf_validate_log_level(const char *key,
32 const char *old_loglevel,
33 const char *new_loglevel,
34 enum conf_update_mode mode)
39 ok = debug_level_parse(new_loglevel, &log_level);
47 static bool logging_conf_validate_location(const char *key,
48 const char *old_location,
49 const char *new_location,
50 enum conf_update_mode mode)
54 ok = logging_validate(new_location);
59 if (mode == CONF_MODE_RELOAD &&
60 strcmp(old_location, new_location) != 0) {
61 D_WARNING("Ignoring update of %s config option \"%s\"\n",
62 LOGGING_CONF_SECTION, key);
69 void logging_conf_init(struct conf_context *conf,
70 const char *default_log_level)
72 const char *log_level;
74 log_level = (default_log_level == NULL) ?
75 LOGGING_LOG_LEVEL_DEFAULT :
78 conf_define_section(conf, LOGGING_CONF_SECTION, NULL);
80 conf_define_string(conf,
82 LOGGING_CONF_LOCATION,
83 LOGGING_LOCATION_DEFAULT,
84 logging_conf_validate_location);
86 conf_define_string(conf,
88 LOGGING_CONF_LOG_LEVEL,
90 logging_conf_validate_log_level);
93 const char *logging_conf_location(struct conf_context *conf)
95 const char *out = NULL;
98 ret = conf_get_string(conf,
100 LOGGING_CONF_LOCATION,
104 /* Can't really happen, but return default */
105 return LOGGING_LOCATION_DEFAULT;
111 const char *logging_conf_log_level(struct conf_context *conf)
113 const char *out = NULL;
116 ret = conf_get_string(conf,
117 LOGGING_CONF_SECTION,
118 LOGGING_CONF_LOG_LEVEL,
122 /* Can't really happen, but return default */
123 return LOGGING_LOG_LEVEL_DEFAULT;