s3:include: Remove trailing whitepaces in MacExtensions.h
[Samba.git] / ctdb / common / logging_conf.c
blob38b3003a3f7a8c1106c2c7ec20a64d0a3a1b9454
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/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 "NOTICE"
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)
36 int log_level;
37 bool ok;
39 ok = debug_level_parse(new_loglevel, &log_level);
40 if (!ok) {
41 return false;
44 return true;
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)
52 bool ok;
54 ok = logging_validate(new_location);
55 if (!ok) {
56 return false;
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);
63 return false;
66 return true;
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 :
76 default_log_level;
78 conf_define_section(conf, LOGGING_CONF_SECTION, NULL);
80 conf_define_string(conf,
81 LOGGING_CONF_SECTION,
82 LOGGING_CONF_LOCATION,
83 LOGGING_LOCATION_DEFAULT,
84 logging_conf_validate_location);
86 conf_define_string(conf,
87 LOGGING_CONF_SECTION,
88 LOGGING_CONF_LOG_LEVEL,
89 log_level,
90 logging_conf_validate_log_level);
93 const char *logging_conf_location(struct conf_context *conf)
95 const char *out = NULL;
96 int ret;
98 ret = conf_get_string(conf,
99 LOGGING_CONF_SECTION,
100 LOGGING_CONF_LOCATION,
101 &out,
102 NULL);
103 if (ret != 0) {
104 /* Can't really happen, but return default */
105 return LOGGING_LOCATION_DEFAULT;
108 return out;
111 const char *logging_conf_log_level(struct conf_context *conf)
113 const char *out = NULL;
114 int ret;
116 ret = conf_get_string(conf,
117 LOGGING_CONF_SECTION,
118 LOGGING_CONF_LOG_LEVEL,
119 &out,
120 NULL);
121 if (ret != 0) {
122 /* Can't really happen, but return default */
123 return LOGGING_LOG_LEVEL_DEFAULT;
126 return out;