4 Copyright (C) Ronnie Sahlberg 2009
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/>.
22 #include "ctdb_logging.h"
24 const char *debug_extra
= "";
28 const char *description
;
31 static struct debug_levels debug_levels
[] = {
33 {DEBUG_WARNING
, "WARNING"},
34 {DEBUG_NOTICE
, "NOTICE"},
36 {DEBUG_DEBUG
, "DEBUG"},
40 const char *get_debug_by_level(int32_t level
)
44 for (i
=0; debug_levels
[i
].description
!= NULL
; i
++) {
45 if (debug_levels
[i
].level
== level
) {
46 return debug_levels
[i
].description
;
52 static bool get_debug_by_desc(const char *desc
, int32_t *level
)
56 for (i
=0; debug_levels
[i
].description
!= NULL
; i
++) {
57 if (!strcasecmp(debug_levels
[i
].description
, desc
)) {
58 *level
= debug_levels
[i
].level
;
66 bool parse_debug(const char *str
, int32_t *level
)
68 if (isalpha(str
[0])) {
69 return get_debug_by_desc(str
, level
);
71 *level
= strtol(str
, NULL
, 0);
72 return get_debug_by_level(*level
) != NULL
;
76 void print_debug_levels(FILE *stream
)
80 for (i
=0; debug_levels
[i
].description
!= NULL
; i
++) {
83 debug_levels
[i
].description
, debug_levels
[i
].level
);