1490eef580b55258010ee4ec925fd65ed9333f0d
[vlendec/samba-autobuild/.git] / ctdb / common / ctdb_logging.c
1 /* 
2    ctdb logging code
3
4    Copyright (C) Ronnie Sahlberg 2009
5
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.
10    
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.
15    
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/>.
18 */
19
20 #include "includes.h"
21 #include "tdb.h"
22 #include "system/time.h"
23 #include "../include/ctdb_private.h"
24 #include "../include/ctdb_client.h"
25
26 int LogLevel = DEBUG_NOTICE;
27 int this_log_level = 0;
28 const char *debug_extra = "";
29
30 struct debug_levels debug_levels[] = {
31         {DEBUG_EMERG,   "EMERG"},
32         {DEBUG_ALERT,   "ALERT"},
33         {DEBUG_CRIT,    "CRIT"},
34         {DEBUG_ERR,     "ERR"},
35         {DEBUG_WARNING, "WARNING"},
36         {DEBUG_NOTICE,  "NOTICE"},
37         {DEBUG_INFO,    "INFO"},
38         {DEBUG_DEBUG,   "DEBUG"},
39         {0, NULL}
40 };
41
42 const char *get_debug_by_level(int32_t level)
43 {
44         int i;
45
46         for (i=0; debug_levels[i].description != NULL; i++) {
47                 if (debug_levels[i].level == level) {
48                         return debug_levels[i].description;
49                 }
50         }
51         return "Unknown";
52 }
53
54 int32_t get_debug_by_desc(const char *desc)
55 {
56         int i;
57
58         for (i=0; debug_levels[i].description != NULL; i++) {
59                 if (!strcasecmp(debug_levels[i].description, desc)) {
60                         return debug_levels[i].level;
61                 }
62         }
63
64         return DEBUG_ERR;
65 }