Code

Added __attribute__((format(printf, ...))) where appropriate.
[sysdb.git] / src / include / utils / error.h
index 487b6e4ffcaa98dffd1202e5667c102fdfcd960e..2c3df32ff48a98c2fe7f26e03fe1593c55acbb82 100644 (file)
@@ -31,9 +31,7 @@
  * will use its own memory region to store information about the last reported
  * error.
  * Once the error message has been passed to SysDB, it will log the entire
- * message at once. XXX: currently, SysDB only supports printing the error to
- * the standard error channel; support for other logging backends will be
- * added later in a modular fashion.
+ * message at once. The message will be sent to all registered log functions.
  */
 
 #ifndef SDB_UTILS_ERROR_H
 extern "C" {
 #endif
 
-/* max length of any error message */
-#ifndef SDB_MAX_ERROR
-#      define SDB_MAX_ERROR 4096
-#endif /* ! SDB_MAX_ERROR */
-
 /* On Linux systems and possibly others, this should be the same as the LOG_
  * constants defined by syslog. */
 enum {
@@ -68,6 +61,15 @@ enum {
                : ((prio) == SDB_LOG_INFO) ? "INFO" \
                : ((prio) == SDB_LOG_DEBUG) ? "DEBUG" : "UNKNOWN")
 
+/*
+ * sdb_error_set_logger:
+ * Set the logging callback to be used for logging messages. By default (or
+ * when explicitely setting the logger to NULL), logs will be written to the
+ * stderr channel.
+ */
+void
+sdb_error_set_logger(int (*f)(int, const char *));
+
 /*
  * sdb_log:
  * Log the specified message. The string will be formatted in printf-style
@@ -78,7 +80,8 @@ enum {
  * on configuration, try a clean shut-down of the process.
  */
 int
-sdb_log(int prio, const char *fmt, ...);
+sdb_log(int prio, const char *fmt, ...)
+               __attribute__((format(printf, 2, 3)));
 
 /*
  * sdb_error_set, sdb_error_append:
@@ -87,9 +90,18 @@ sdb_log(int prio, const char *fmt, ...);
  * be done.
  */
 int
-sdb_error_set(const char *fmt, ...);
+sdb_error_set(const char *fmt, ...)
+               __attribute__((format(printf, 1, 2)));
+int
+sdb_error_append(const char *fmt, ...)
+               __attribute__((format(printf, 1, 2)));
+
+/*
+ * sdb_error_chomp:
+ * Remove all consecutive newline characters at the end of the error message.
+ */
 int
-sdb_error_append(const char *fmt, ...);
+sdb_error_chomp(void);
 
 /*
  * sdb_error_log: