2 logging wrapper for libctdb
4 Copyright (C) Ronnie Sahlberg 2010
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 <sys/socket.h>
26 #include "libctdb_private.h"
28 int ctdb_log_level = LOG_WARNING;
30 void ctdb_do_debug(struct ctdb_connection *ctdb,
31 int severity, const char *format, ...)
36 ctdb->log(ctdb->log_priv, severity, format, ap);
40 /* Attach tdb logging to our ctdb logging. */
41 void ctdb_tdb_log_bridge(struct tdb_context *tdb,
42 enum tdb_debug_level level,
43 const char *format, ...)
47 struct ctdb_connection *ctdb = tdb_get_logging_private(tdb);
57 case TDB_DEBUG_WARNING:
67 if (sev > ctdb_log_level) {
71 newformat = malloc(sizeof("TDB error: ") + strlen(format));
74 "memory allocation failure reporting tdb error %s",
79 /* Prepend TDB error: and remove \n */
80 strcpy(newformat, "TDB error: ");
81 strcat(newformat, format);
82 if (newformat[strlen(newformat)-1] == '\n')
83 newformat[strlen(newformat)-1] = '\0';
86 ctdb->log(ctdb->log_priv, sev, newformat, ap);
91 /* Convenient log helper. */
92 void ctdb_log_file(FILE *outf, int priority, const char *format, va_list ap)
95 priority == LOG_EMERG ? "EMERG" :
96 priority == LOG_ALERT ? "ALERT" :
97 priority == LOG_CRIT ? "CRIT" :
98 priority == LOG_ERR ? "ERR" :
99 priority == LOG_WARNING ? "WARNING" :
100 priority == LOG_NOTICE ? "NOTICE" :
101 priority == LOG_INFO ? "INFO" :
102 priority == LOG_DEBUG ? "DEBUG" :
103 "Unknown Error Level");
105 vfprintf(outf, format, ap);
106 if (priority == LOG_ERR) {
107 fprintf(outf, " (%s)", strerror(errno));