ctdb-server: Use find_public_ip_vnn() in a couple of extra places
[samba4-gss.git] / ctdb / conf / logging_conf.c
blobfb1c3735c0e717d8b489f1f40ef2865b80dfca3e
1 /*
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/>.
20 #include "replace.h"
22 #include <talloc.h>
24 #include "common/logging.h"
26 #include "conf/conf.h"
27 #include "conf/logging_conf.h"
29 #define LOGGING_LOCATION_DEFAULT "file:" LOGDIR "/log.ctdb"
30 #define LOGGING_LOG_LEVEL_DEFAULT "NOTICE"
32 static bool logging_conf_validate_log_level(const char *key,
33 const char *old_loglevel,
34 const char *new_loglevel,
35 enum conf_update_mode mode)
37 int log_level;
38 bool ok;
40 ok = debug_level_parse(new_loglevel, &log_level);
41 if (!ok) {
42 return false;
45 return true;
48 static bool logging_conf_validate_location(const char *key,
49 const char *old_location,
50 const char *new_location,
51 enum conf_update_mode mode)
53 bool ok;
55 ok = logging_validate(new_location);
56 if (!ok) {
57 return false;
60 if (mode == CONF_MODE_RELOAD &&
61 strcmp(old_location, new_location) != 0) {
62 D_WARNING("Ignoring update of %s config option \"%s\"\n",
63 LOGGING_CONF_SECTION, key);
64 return false;
67 return true;
70 void logging_conf_init(struct conf_context *conf,
71 const char *default_log_level)
73 const char *log_level;
75 log_level = (default_log_level == NULL) ?
76 LOGGING_LOG_LEVEL_DEFAULT :
77 default_log_level;
79 conf_define_section(conf, LOGGING_CONF_SECTION, NULL);
81 conf_define_string(conf,
82 LOGGING_CONF_SECTION,
83 LOGGING_CONF_LOCATION,
84 LOGGING_LOCATION_DEFAULT,
85 logging_conf_validate_location);
87 conf_define_string(conf,
88 LOGGING_CONF_SECTION,
89 LOGGING_CONF_LOG_LEVEL,
90 log_level,
91 logging_conf_validate_log_level);
94 const char *logging_conf_location(struct conf_context *conf)
96 const char *out = NULL;
97 int ret;
99 ret = conf_get_string(conf,
100 LOGGING_CONF_SECTION,
101 LOGGING_CONF_LOCATION,
102 &out,
103 NULL);
104 if (ret != 0) {
105 /* Can't really happen, but return default */
106 return LOGGING_LOCATION_DEFAULT;
109 return out;
112 const char *logging_conf_log_level(struct conf_context *conf)
114 const char *out = NULL;
115 int ret;
117 ret = conf_get_string(conf,
118 LOGGING_CONF_SECTION,
119 LOGGING_CONF_LOG_LEVEL,
120 &out,
121 NULL);
122 if (ret != 0) {
123 /* Can't really happen, but return default */
124 return LOGGING_LOG_LEVEL_DEFAULT;
127 return out;