[PATCH] Weston: log.c, log.h: the files themselves

Martin Minarik minarik11 at student.fiit.stuba.sk
Sat May 26 11:44:40 PDT 2012


---
 src/log.c |   85 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 src/log.h |   36 ++++++++++++++++++++++++++
 2 files changed, 121 insertions(+), 0 deletions(-)
 create mode 100644 src/log.c
 create mode 100644 src/log.h

diff --git a/src/log.c b/src/log.c
new file mode 100644
index 0000000..4d9d61c
--- /dev/null
+++ b/src/log.c
@@ -0,0 +1,85 @@
+/*
+ * Copyright © 2012 Martin Minarik
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and
+ * its documentation for any purpose is hereby granted without fee, provided
+ * that the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the name of the copyright holders not be used in
+ * advertising or publicity pertaining to distribution of the software
+ * without specific, written prior permission.  The copyright holders make
+ * no representations about the suitability of this software for any
+ * purpose.  It is provided "as is" without express or implied warranty.
+ *
+ * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
+ * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
+ * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
+ * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+ * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include <stdio.h>
+#include <stdarg.h>
+
+#include <wayland-util.h>
+
+static FILE *weston_logfile = NULL;
+
+static int
+weston_log_noop_handler(const char *fmt, va_list arg)
+{
+	return 0;
+}
+
+static int
+weston_log_fprintf_logfile_handler(const char *fmt, va_list arg)
+{
+	int l;
+	l = vfprintf(weston_logfile, fmt, arg);
+	fflush(weston_logfile);
+	return l;
+}
+
+static int
+weston_log_fprintf_stderr_handler(const char *fmt, va_list arg)
+{
+	return vfprintf(stderr, fmt, arg);
+}
+
+static wl_log_func_t weston_logfile_handler = weston_log_noop_handler;
+
+int
+weston_log_duplicator(const char *fmt, va_list arg)
+{
+	weston_log_fprintf_stderr_handler(fmt, arg);
+	return weston_logfile_handler(fmt, arg);
+}
+
+static wl_log_func_t wl_weston_handler = weston_log_duplicator;
+
+void
+weston_log_file_create(const char *filename)
+{
+	weston_logfile = fopen(filename, "w");
+	if (weston_logfile != NULL)
+		weston_logfile_handler = weston_log_fprintf_logfile_handler;
+}
+
+void
+weston_log_file_destroy()
+{
+	fclose(weston_logfile);
+}
+
+WL_EXPORT int
+weston_log(const char *fmt, ...)
+{
+	int l;
+	va_list argp;
+	va_start(argp, fmt);
+	l = weston_log_duplicator(fmt, argp);
+	va_end(argp);
+	return l;
+}
diff --git a/src/log.h b/src/log.h
new file mode 100644
index 0000000..4000aa2
--- /dev/null
+++ b/src/log.h
@@ -0,0 +1,36 @@
+/*
+ * Copyright © 2012 Martin Minarik
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and
+ * its documentation for any purpose is hereby granted without fee, provided
+ * that the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the name of the copyright holders not be used in
+ * advertising or publicity pertaining to distribution of the software
+ * without specific, written prior permission.  The copyright holders make
+ * no representations about the suitability of this software for any
+ * purpose.  It is provided "as is" without express or implied warranty.
+ *
+ * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
+ * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
+ * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
+ * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+ * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include <stdarg.h>
+
+#ifndef _WAYLAND_SYSTEM_LOG_H_
+#define _WAYLAND_SYSTEM_LOG_H_
+
+void weston_log_file_create(const char *filename);
+void weston_log_file_destroy();
+
+int weston_log_duplicator(const char *fmt, va_list arg);
+
+int weston_log(const char *fmt, ...);
+#define W_PRINTF(...) weston_log(__VA_ARGS__)
+
+#endif
-- 
1.7.5.4



More information about the wayland-devel mailing list