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/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
)
40 ok
= debug_level_parse(new_loglevel
, &log_level
);
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
)
55 ok
= logging_validate(new_location
);
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
);
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
:
79 conf_define_section(conf
, LOGGING_CONF_SECTION
, NULL
);
81 conf_define_string(conf
,
83 LOGGING_CONF_LOCATION
,
84 LOGGING_LOCATION_DEFAULT
,
85 logging_conf_validate_location
);
87 conf_define_string(conf
,
89 LOGGING_CONF_LOG_LEVEL
,
91 logging_conf_validate_log_level
);
94 const char *logging_conf_location(struct conf_context
*conf
)
96 const char *out
= NULL
;
99 ret
= conf_get_string(conf
,
100 LOGGING_CONF_SECTION
,
101 LOGGING_CONF_LOCATION
,
105 /* Can't really happen, but return default */
106 return LOGGING_LOCATION_DEFAULT
;
112 const char *logging_conf_log_level(struct conf_context
*conf
)
114 const char *out
= NULL
;
117 ret
= conf_get_string(conf
,
118 LOGGING_CONF_SECTION
,
119 LOGGING_CONF_LOG_LEVEL
,
123 /* Can't really happen, but return default */
124 return LOGGING_LOG_LEVEL_DEFAULT
;