ctdb-daemon: Fix typo in debug message
[Samba.git] / ctdb / common / ctdb_logging.c
blobe76966c822c83a91983bf885dd6b6bac126c4469
1 /*
2 ctdb logging code
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/>.
20 #include <ctype.h>
21 #include "replace.h"
22 #include "ctdb_logging.h"
24 const char *debug_extra = "";
26 struct debug_levels {
27 int32_t level;
28 const char *description;
31 static struct debug_levels debug_levels[] = {
32 {DEBUG_ERR, "ERR"},
33 {DEBUG_WARNING, "WARNING"},
34 {DEBUG_NOTICE, "NOTICE"},
35 {DEBUG_INFO, "INFO"},
36 {DEBUG_DEBUG, "DEBUG"},
37 {0, NULL}
40 const char *get_debug_by_level(int32_t level)
42 int i;
44 for (i=0; debug_levels[i].description != NULL; i++) {
45 if (debug_levels[i].level == level) {
46 return debug_levels[i].description;
49 return NULL;
52 static bool get_debug_by_desc(const char *desc, int32_t *level)
54 int i;
56 for (i=0; debug_levels[i].description != NULL; i++) {
57 if (!strcasecmp(debug_levels[i].description, desc)) {
58 *level = debug_levels[i].level;
59 return true;
63 return false;
66 bool parse_debug(const char *str, int32_t *level)
68 if (isalpha(str[0])) {
69 return get_debug_by_desc(str, level);
70 } else {
71 *level = strtol(str, NULL, 0);
72 return get_debug_by_level(*level) != NULL;
76 void print_debug_levels(FILE *stream)
78 int i;
80 for (i=0; debug_levels[i].description != NULL; i++) {
81 fprintf(stream,
82 "%s (%d)\n",
83 debug_levels[i].description, debug_levels[i].level);