ucx/logging.c

changeset 1
1bcaac272cdf
child 5
88625853ae74
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ucx/logging.c	Fri Nov 30 21:18:13 2012 +0100
@@ -0,0 +1,20 @@
+#include "logging.h"
+#include <stdlib.h>
+
+UcxLogger *ucx_logger_new(FILE *stream, unsigned int level) {
+    UcxLogger *logger = (UcxLogger*) malloc(sizeof(UcxLogger));
+    if (logger != NULL) {
+        logger->stream = stream;
+        logger->level = level;
+    }
+
+    return logger;
+}
+
+void ucx_logger_log(UcxLogger *logger, unsigned int level,
+        const sstr_t message) {
+    if (level <= logger->level) {
+        fwrite(message.ptr, 1, message.length, logger->stream);
+        fflush(logger->stream);
+    }
+}

mercurial