[PATCH v4 2/2] Weston: Replace fprintf() by weston_log()

Martin Minarik minarik11 at student.fiit.stuba.sk
Thu May 31 13:48:44 PDT 2012


Now it is possible removing include stdio as well.
---
 src/compositor-drm.c          |  105 ++++++++++++++++++++---------------------
 src/compositor-openwfd.c      |   38 +++++++-------
 src/compositor-wayland.c      |   27 ++++++-----
 src/compositor-x11.c          |   22 ++++----
 src/compositor.c              |   57 +++++++++++------------
 src/evdev.c                   |   12 ++--
 src/shell.c                   |   15 +++---
 src/tablet-shell.c            |   11 ++--
 src/tty.c                     |   33 ++++++-------
 src/xwayland/launcher.c       |   30 ++++++------
 src/xwayland/selection.c      |   52 ++++++++++----------
 src/xwayland/window-manager.c |   74 ++++++++++++++---------------
 12 files changed, 235 insertions(+), 241 deletions(-)

diff --git a/src/compositor-drm.c b/src/compositor-drm.c
index ce024dd..503abf5 100644
--- a/src/compositor-drm.c
+++ b/src/compositor-drm.c
@@ -24,7 +24,6 @@
 #define _GNU_SOURCE
 
 #include <errno.h>
-#include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 #include <fcntl.h>
@@ -41,6 +40,7 @@
 #include "compositor.h"
 #include "evdev.h"
 #include "launcher-util.h"
+#include "log.h"
 
 struct drm_compositor {
 	struct weston_compositor base;
@@ -206,7 +206,7 @@ drm_fb_get_from_bo(struct gbm_bo *bo, struct drm_output *output)
 	ret = drmModeAddFB(compositor->drm.fd, width, height, 24, 32,
 			   stride, handle, &fb->fb_id);
 	if (ret) {
-		fprintf(stderr, "failed to create kms fb: %m\n");
+		weston_log("failed to create kms fb: %m\n");
 		free(fb);
 		return NULL;
 	}
@@ -292,7 +292,7 @@ drm_output_render(struct drm_output *output, pixman_region32_t *damage)
 
 	if (!eglMakeCurrent(compositor->base.display, output->egl_surface,
 			    output->egl_surface, compositor->base.context)) {
-		fprintf(stderr, "failed to make current\n");
+		weston_log("failed to make current\n");
 		return;
 	}
 
@@ -304,13 +304,13 @@ drm_output_render(struct drm_output *output, pixman_region32_t *damage)
 	eglSwapBuffers(compositor->base.display, output->egl_surface);
 	bo = gbm_surface_lock_front_buffer(output->surface);
 	if (!bo) {
-		fprintf(stderr, "failed to lock front buffer: %m\n");
+		weston_log("failed to lock front buffer: %m\n");
 		return;
 	}
 
 	output->next = drm_fb_get_from_bo(bo, output);
 	if (!output->next) {
-		fprintf(stderr, "failed to get drm_fb for bo\n");
+		weston_log("failed to get drm_fb for bo\n");
 		gbm_surface_release_buffer(output->surface, bo);
 		return;
 	}
@@ -340,7 +340,7 @@ drm_output_repaint(struct weston_output *output_base,
 				     &output->connector_id, 1,
 				     &mode->mode_info);
 		if (ret) {
-			fprintf(stderr, "set mode failed: %m\n");
+			weston_log("set mode failed: %m\n");
 			return;
 		}
 	}
@@ -348,7 +348,7 @@ drm_output_repaint(struct weston_output *output_base,
 	if (drmModePageFlip(compositor->drm.fd, output->crtc_id,
 			    output->next->fb_id,
 			    DRM_MODE_PAGE_FLIP_EVENT, output) < 0) {
-		fprintf(stderr, "queueing pageflip failed: %m\n");
+		weston_log("queueing pageflip failed: %m\n");
 		return;
 	}
 
@@ -372,7 +372,7 @@ drm_output_repaint(struct weston_output *output_base,
 				      s->src_x, s->src_y,
 				      s->src_w, s->src_h);
 		if (ret)
-			fprintf(stderr, "setplane failed: %d: %s\n",
+			weston_log("setplane failed: %d: %s\n",
 				ret, strerror(errno));
 
 		/*
@@ -382,7 +382,7 @@ drm_output_repaint(struct weston_output *output_base,
 		vbl.request.signal = (unsigned long)s;
 		ret = drmWaitVBlank(compositor->drm.fd, &vbl);
 		if (ret) {
-			fprintf(stderr, "vblank event request failed: %d: %s\n",
+			weston_log("vblank event request failed: %d: %s\n",
 				ret, strerror(errno));
 		}
 	}
@@ -488,8 +488,7 @@ drm_disable_unused_sprites(struct weston_output *output_base)
 				      output->crtc_id, 0, 0,
 				      0, 0, 0, 0, 0, 0, 0, 0);
 		if (ret)
-			fprintf(stderr,
-				"failed to disable plane: %d: %s\n",
+			weston_log("failed to disable plane: %d: %s\n",
 				ret, strerror(errno));
 		drmModeRmFB(c->drm.fd, s->fb_id);
 		s->surface = NULL;
@@ -574,7 +573,7 @@ drm_output_prepare_overlay_surface(struct weston_output *output_base,
 			    format, handles, pitches, offsets,
 			    &fb_id, 0);
 	if (ret) {
-		fprintf(stderr, "addfb2 failed: %d\n", ret);
+		weston_log("addfb2 failed: %d\n", ret);
 		c->sprites_are_broken = 1;
 		return -1;
 	}
@@ -769,7 +768,7 @@ drm_output_set_cursor(struct weston_output *output_base,
 	handle = gbm_bo_get_handle(bo).s32;
 	ret = drmModeSetCursor(c->drm.fd, output->crtc_id, handle, 64, 64);
 	if (ret) {
-		fprintf(stderr, "failed to set cursor: %s\n", strerror(-ret));
+		weston_log("failed to set cursor: %s\n", strerror(-ret));
 		goto out;
 	}
 
@@ -777,7 +776,7 @@ drm_output_set_cursor(struct weston_output *output_base,
 				es->sprite->geometry.x - output->base.x,
 				es->sprite->geometry.y - output->base.y);
 	if (ret) {
-		fprintf(stderr, "failed to move cursor: %s\n", strerror(-ret));
+		weston_log("failed to move cursor: %s\n", strerror(-ret));
 		goto out;
 	}
 
@@ -855,12 +854,12 @@ drm_output_switch_mode(struct weston_output *output_base, struct weston_mode *mo
 	EGLSurface egl_surface;
 
 	if (output_base == NULL) {
-		fprintf(stderr, "output is NULL.\n");
+		weston_log("output is NULL.\n");
 		return -1;
 	}
 
 	if (mode == NULL) {
-		fprintf(stderr, "mode is NULL.\n");
+		weston_log("mode is NULL.\n");
 		return -1;
 	}
 
@@ -869,7 +868,7 @@ drm_output_switch_mode(struct weston_output *output_base, struct weston_mode *mo
 	drm_mode  = choose_mode (output, mode);
 
 	if (!drm_mode) {
-		printf("%s, invalid resolution:%dx%d\n", __func__, mode->width, mode->height);
+		weston_log("%s, invalid resolution:%dx%d\n", __func__, mode->width, mode->height);
 		return -1;
 	} else if (&drm_mode->base == output->base.current) {
 		return 0;
@@ -882,7 +881,7 @@ drm_output_switch_mode(struct weston_output *output_base, struct weston_mode *mo
 				     &output->connector_id, 1, &drm_mode->mode_info);
 
 		if (ret) {
-			fprintf(stderr, "failed to set mode (%dx%d) %u Hz\n",
+			weston_log("failed to set mode (%dx%d) %u Hz\n",
 				drm_mode->base.width,
 				drm_mode->base.height,
 				drm_mode->base.refresh / 1000);
@@ -908,7 +907,7 @@ drm_output_switch_mode(struct weston_output *output_base, struct weston_mode *mo
 				 GBM_BO_USE_SCANOUT |
 				 GBM_BO_USE_RENDERING);
 	if (!surface) {
-		fprintf(stderr, "failed to create gbm surface\n");
+		weston_log("failed to create gbm surface\n");
 		return -1;
 	}
 
@@ -918,7 +917,7 @@ drm_output_switch_mode(struct weston_output *output_base, struct weston_mode *mo
 				       surface, NULL);
 
 	if (egl_surface == EGL_NO_SURFACE) {
-		fprintf(stderr, "failed to create egl surface\n");
+		weston_log("failed to create egl surface\n");
 		goto err;
 	}
 
@@ -927,7 +926,7 @@ drm_output_switch_mode(struct weston_output *output_base, struct weston_mode *mo
 			     output->current->fb_id, 0, 0,
 			     &output->connector_id, 1, &drm_mode->mode_info);
 	if (ret) {
-		fprintf(stderr, "failed to set mode\n");
+		weston_log("failed to set mode\n");
 		goto err;
 	}
 
@@ -1006,7 +1005,7 @@ init_egl(struct drm_compositor *ec, struct udev_device *device)
 	if (sysnum)
 		ec->drm.id = atoi(sysnum);
 	if (!sysnum || ec->drm.id < 0) {
-		fprintf(stderr, "cannot get device sysnum\n");
+		weston_log("cannot get device sysnum\n");
 		return -1;
 	}
 
@@ -1014,7 +1013,7 @@ init_egl(struct drm_compositor *ec, struct udev_device *device)
 	fd = open(filename, O_RDWR | O_CLOEXEC);
 	if (fd < 0) {
 		/* Probably permissions error */
-		fprintf(stderr, "couldn't open %s, skipping\n",
+		weston_log("couldn't open %s, skipping\n",
 			udev_device_get_devnode(device));
 		return -1;
 	}
@@ -1023,30 +1022,30 @@ init_egl(struct drm_compositor *ec, struct udev_device *device)
 	ec->gbm = gbm_create_device(ec->drm.fd);
 	ec->base.display = eglGetDisplay(ec->gbm);
 	if (ec->base.display == NULL) {
-		fprintf(stderr, "failed to create display\n");
+		weston_log("failed to create display\n");
 		return -1;
 	}
 
 	if (!eglInitialize(ec->base.display, &major, &minor)) {
-		fprintf(stderr, "failed to initialize display\n");
+		weston_log("failed to initialize display\n");
 		return -1;
 	}
 
 	if (!eglBindAPI(EGL_OPENGL_ES_API)) {
-		fprintf(stderr, "failed to bind api EGL_OPENGL_ES_API\n");
+		weston_log("failed to bind api EGL_OPENGL_ES_API\n");
 		return -1;
 	}
 
 	if (!eglChooseConfig(ec->base.display, config_attribs,
 			     &ec->base.config, 1, &n) || n != 1) {
-		fprintf(stderr, "failed to choose config: %d\n", n);
+		weston_log("failed to choose config: %d\n", n);
 		return -1;
 	}
 
 	ec->base.context = eglCreateContext(ec->base.display, ec->base.config,
 					    EGL_NO_CONTEXT, context_attribs);
 	if (ec->base.context == NULL) {
-		fprintf(stderr, "failed to create context\n");
+		weston_log("failed to create context\n");
 		return -1;
 	}
 
@@ -1054,7 +1053,7 @@ init_egl(struct drm_compositor *ec, struct udev_device *device)
 					       GBM_FORMAT_XRGB8888,
 					       GBM_BO_USE_RENDERING);
 	if (!ec->dummy_surface) {
-		fprintf(stderr, "failed to create dummy gbm surface\n");
+		weston_log("failed to create dummy gbm surface\n");
 		return -1;
 	}
 
@@ -1062,13 +1061,13 @@ init_egl(struct drm_compositor *ec, struct udev_device *device)
 		eglCreateWindowSurface(ec->base.display, ec->base.config,
 				       ec->dummy_surface, NULL);
 	if (ec->dummy_egl_surface == EGL_NO_SURFACE) {
-		fprintf(stderr, "failed to create egl surface\n");
+		weston_log("failed to create egl surface\n");
 		return -1;
 	}
 
 	if (!eglMakeCurrent(ec->base.display, ec->dummy_egl_surface,
 			    ec->dummy_egl_surface, ec->base.context)) {
-		fprintf(stderr, "failed to make context current\n");
+		weston_log("failed to make context current\n");
 		return -1;
 	}
 
@@ -1252,7 +1251,7 @@ create_output_for_connector(struct drm_compositor *ec,
 
 	encoder = drmModeGetEncoder(ec->drm.fd, connector->encoders[0]);
 	if (encoder == NULL) {
-		fprintf(stderr, "No encoder for connector.\n");
+		weston_log("No encoder for connector.\n");
 		return -1;
 	}
 
@@ -1262,7 +1261,7 @@ create_output_for_connector(struct drm_compositor *ec,
 			break;
 	}
 	if (i == resources->count_crtcs) {
-		fprintf(stderr, "No usable crtc for encoder.\n");
+		weston_log("No usable crtc for encoder.\n");
 		drmModeFreeEncoder(encoder);
 		return -1;
 	}
@@ -1312,7 +1311,7 @@ create_output_for_connector(struct drm_compositor *ec,
 					     GBM_BO_USE_SCANOUT |
 					     GBM_BO_USE_RENDERING);
 	if (!output->surface) {
-		fprintf(stderr, "failed to create gbm surface\n");
+		weston_log("failed to create gbm surface\n");
 		goto err_free;
 	}
 
@@ -1320,7 +1319,7 @@ create_output_for_connector(struct drm_compositor *ec,
 		eglCreateWindowSurface(ec->base.display, ec->base.config,
 				       output->surface, NULL);
 	if (output->egl_surface == EGL_NO_SURFACE) {
-		fprintf(stderr, "failed to create egl surface\n");
+		weston_log("failed to create egl surface\n");
 		goto err_surface;
 	}
 
@@ -1380,7 +1379,7 @@ create_sprites(struct drm_compositor *ec)
 
 	plane_res = drmModeGetPlaneResources(ec->drm.fd);
 	if (!plane_res) {
-		fprintf(stderr, "failed to get plane resources: %s\n",
+		weston_log("failed to get plane resources: %s\n",
 			strerror(errno));
 		return;
 	}
@@ -1393,7 +1392,7 @@ create_sprites(struct drm_compositor *ec)
 		sprite = malloc(sizeof(*sprite) + ((sizeof(uint32_t)) *
 						   plane->count_formats));
 		if (!sprite) {
-			fprintf(stderr, "%s: out of memory\n",
+			weston_log("%s: out of memory\n",
 				__func__);
 			free(plane);
 			continue;
@@ -1453,7 +1452,7 @@ create_outputs(struct drm_compositor *ec, uint32_t option_connector,
 
 	resources = drmModeGetResources(ec->drm.fd);
 	if (!resources) {
-		fprintf(stderr, "drmModeGetResources failed\n");
+		weston_log("drmModeGetResources failed\n");
 		return -1;
 	}
 
@@ -1491,7 +1490,7 @@ create_outputs(struct drm_compositor *ec, uint32_t option_connector,
 	}
 
 	if (wl_list_empty(&ec->base.output_list)) {
-		fprintf(stderr, "No currently active connector found.\n");
+		weston_log("No currently active connector found.\n");
 		drmModeFreeResources(resources);
 		return -1;
 	}
@@ -1514,7 +1513,7 @@ update_outputs(struct drm_compositor *ec, struct udev_device *drm_device)
 
 	resources = drmModeGetResources(ec->drm.fd);
 	if (!resources) {
-		fprintf(stderr, "drmModeGetResources failed\n");
+		weston_log("drmModeGetResources failed\n");
 		return;
 	}
 
@@ -1547,7 +1546,7 @@ update_outputs(struct drm_compositor *ec, struct udev_device *drm_device)
 			create_output_for_connector(ec, resources,
 						    connector, x, y,
 						    drm_device);
-			printf("connector %d connected\n", connector_id);
+			weston_log("connector %d connected\n", connector_id);
 
 		}
 		drmModeFreeConnector(connector);
@@ -1566,7 +1565,7 @@ update_outputs(struct drm_compositor *ec, struct udev_device *drm_device)
 
 			if (disconnects & (1 << output->connector_id)) {
 				disconnects &= ~(1 << output->connector_id);
-				printf("connector %d disconnected\n",
+				weston_log("connector %d disconnected\n",
 				       output->connector_id);
 				x_offset += output->base.current->width;
 				drm_output_destroy(&output->base);
@@ -1635,7 +1634,7 @@ drm_destroy(struct weston_compositor *ec)
 	gbm_device_destroy(d->gbm);
 	destroy_sprites(d);
 	if (weston_launcher_drm_set_master(&d->base, d->drm.fd, 0) < 0)
-		fprintf(stderr, "failed to drop master: %m\n");
+		weston_log("failed to drop master: %m\n");
 	tty_destroy(d->tty);
 
 	free(d);
@@ -1655,7 +1654,7 @@ drm_compositor_set_modes(struct drm_compositor *compositor)
 				     &output->connector_id, 1,
 				     &drm_mode->mode_info);
 		if (ret < 0) {
-			fprintf(stderr,
+			weston_log(
 				"failed to set mode %dx%d for output at %d,%d: %m\n",
 				drm_mode->base.width, drm_mode->base.height, 
 				output->base.x, output->base.y);
@@ -1676,7 +1675,7 @@ vt_func(struct weston_compositor *compositor, int event)
 	case TTY_ENTER_VT:
 		compositor->focus = 1;
 		if (weston_launcher_drm_set_master(&ec->base, ec->drm.fd, 1)) {
-			fprintf(stderr, "failed to set master: %m\n");
+			weston_log("failed to set master: %m\n");
 			wl_display_terminate(compositor->wl_display);
 		}
 		compositor->state = ec->prev_state;
@@ -1720,7 +1719,7 @@ vt_func(struct weston_compositor *compositor, int event)
 					0, 0, 0, 0, 0, 0, 0, 0);
 
 		if (weston_launcher_drm_set_master(&ec->base, ec->drm.fd, 0) < 0)
-			fprintf(stderr, "failed to drop master: %m\n");
+			weston_log("failed to drop master: %m\n");
 
 		break;
 	};
@@ -1757,14 +1756,14 @@ drm_compositor_create(struct wl_display *display,
 	memset(ec, 0, sizeof *ec);
 	ec->udev = udev_new();
 	if (ec->udev == NULL) {
-		fprintf(stderr, "failed to initialize udev context\n");
+		weston_log("failed to initialize udev context\n");
 		return NULL;
 	}
 
 	ec->base.wl_display = display;
 	ec->tty = tty_create(&ec->base, vt_func, tty);
 	if (!ec->tty) {
-		fprintf(stderr, "failed to initialize tty\n");
+		weston_log("failed to initialize tty\n");
 		free(ec);
 		return NULL;
 	}
@@ -1790,12 +1789,12 @@ drm_compositor_create(struct wl_display *display,
 	}
 
 	if (drm_device == NULL) {
-		fprintf(stderr, "no drm device found\n");
+		weston_log("no drm device found\n");
 		return NULL;
 	}
 
 	if (init_egl(ec, drm_device) < 0) {
-		fprintf(stderr, "failed to initialize egl\n");
+		weston_log("failed to initialize egl\n");
 		return NULL;
 	}
 
@@ -1818,7 +1817,7 @@ drm_compositor_create(struct wl_display *display,
 	create_sprites(ec);
 
 	if (create_outputs(ec, connector, drm_device) < 0) {
-		fprintf(stderr, "failed to create output for %s\n", path);
+		weston_log("failed to create output for %s\n", path);
 		return NULL;
 	}
 
@@ -1835,7 +1834,7 @@ drm_compositor_create(struct wl_display *display,
 
 	ec->udev_monitor = udev_monitor_new_from_netlink(ec->udev, "udev");
 	if (ec->udev_monitor == NULL) {
-		fprintf(stderr, "failed to intialize udev monitor\n");
+		weston_log("failed to intialize udev monitor\n");
 		return NULL;
 	}
 	udev_monitor_filter_add_match_subsystem_devtype(ec->udev_monitor,
@@ -1846,7 +1845,7 @@ drm_compositor_create(struct wl_display *display,
 				     WL_EVENT_READABLE, udev_drm_event, ec);
 
 	if (udev_monitor_enable_receiving(ec->udev_monitor) < 0) {
-		fprintf(stderr, "failed to enable udev-monitor receiving\n");
+		weston_log("failed to enable udev-monitor receiving\n");
 		return NULL;
 	}
 
diff --git a/src/compositor-openwfd.c b/src/compositor-openwfd.c
index 3548dfb..aac8064 100644
--- a/src/compositor-openwfd.c
+++ b/src/compositor-openwfd.c
@@ -23,7 +23,6 @@
 
 #define _GNU_SOURCE
 
-#include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 
@@ -36,6 +35,7 @@
 
 #include "compositor.h"
 #include "evdev.h"
+#include "log.h"
 
 struct wfd_compositor {
 	struct weston_compositor base;
@@ -137,36 +137,36 @@ init_egl(struct wfd_compositor *ec)
 	ec->gbm = gbm_create_device(ec->wfd_fd);
 	ec->base.display = eglGetDisplay(ec->gbm);
 	if (ec->base.display == NULL) {
-		fprintf(stderr, "failed to create display\n");
+		weston_log("failed to create display\n");
 		return -1;
 	}
 
 	if (!eglInitialize(ec->base.display, &major, &minor)) {
-		fprintf(stderr, "failed to initialize display\n");
+		weston_log("failed to initialize display\n");
 		return -1;
 	}
 
 	extensions = eglQueryString(ec->base.display, EGL_EXTENSIONS);
 	if (!strstr(extensions, "EGL_KHR_surfaceless_gles2")) {
-		fprintf(stderr, "EGL_KHR_surfaceless_gles2 not available\n");
+		weston_log("EGL_KHR_surfaceless_gles2 not available\n");
 		return -1;
 	}
 
 	if (!eglBindAPI(EGL_OPENGL_ES_API)) {
-		fprintf(stderr, "failed to bind api EGL_OPENGL_ES_API\n");
+		weston_log("failed to bind api EGL_OPENGL_ES_API\n");
 		return -1;
 	}
 
 	ec->base.context = eglCreateContext(ec->base.display, NULL,
 					    EGL_NO_CONTEXT, context_attribs);
 	if (ec->base.context == NULL) {
-		fprintf(stderr, "failed to create context\n");
+		weston_log("failed to create context\n");
 		return -1;
 	}
 
 	if (!eglMakeCurrent(ec->base.display, EGL_NO_SURFACE,
 			    EGL_NO_SURFACE, ec->base.context)) {
-		fprintf(stderr, "failed to make context current\n");
+		weston_log("failed to make context current\n");
 		return -1;
 	}
 
@@ -272,7 +272,7 @@ create_output_for_port(struct wfd_compositor *ec,
 
 	num_modes = wfdGetPortModes(ec->dev, output->port, NULL, 0);
 	if (num_modes < 1) {
-		fprintf(stderr, "failed to get port mode\n");
+		weston_log("failed to get port mode\n");
 		goto cleanup_port;
 	}
 
@@ -300,7 +300,7 @@ create_output_for_port(struct wfd_compositor *ec,
 		}
 	}
 	if (output->base.current == NULL) {
-		fprintf(stderr, "failed to find a native mode\n");
+		weston_log("failed to find a native mode\n");
 		goto cleanup_port;
 	}
 
@@ -314,7 +314,7 @@ create_output_for_port(struct wfd_compositor *ec,
 	num_pipelines = wfdGetPortAttribi(ec->dev, output->port,
 					  WFD_PORT_PIPELINE_ID_COUNT);
 	if (num_pipelines < 1) {
-		fprintf(stderr, "failed to get a bindable pipeline\n");
+		weston_log("failed to get a bindable pipeline\n");
 		goto cleanup_port;
 	}
 	pipelines = calloc(num_pipelines, sizeof *pipelines);
@@ -333,7 +333,7 @@ create_output_for_port(struct wfd_compositor *ec,
 		}
 	}
 	if (output->pipeline_id == WFD_INVALID_PIPELINE_ID) {
-		fprintf(stderr, "no pipeline found for port: %d\n", port);
+		weston_log("no pipeline found for port: %d\n", port);
 		goto cleanup_pipelines;
 	}
 
@@ -348,7 +348,7 @@ create_output_for_port(struct wfd_compositor *ec,
 
 	output->pipeline = wfdCreatePipeline(ec->dev, output->pipeline_id, NULL);
 	if (output->pipeline == WFD_INVALID_HANDLE) {
-		fprintf(stderr, "failed to create a pipeline\n");
+		weston_log("failed to create a pipeline\n");
 		goto cleanup_weston_output;
 	}
 
@@ -367,7 +367,7 @@ create_output_for_port(struct wfd_compositor *ec,
 							 EGL_NATIVE_PIXMAP_KHR,
 							 output->bo[i], NULL);
 
-		printf("output->image[i]: %p\n", output->image[i]);
+		weston_log("output->image[i]: %p\n", output->image[i]);
 		ec->base.image_target_renderbuffer_storage(GL_RENDERBUFFER,
 							   output->image[i]);
 		output->source[i] =
@@ -375,7 +375,7 @@ create_output_for_port(struct wfd_compositor *ec,
 						 output->image[i], NULL);
 
 		if (output->source[i] == WFD_INVALID_HANDLE) {
-			fprintf(stderr, "failed to create source\n");
+			weston_log("failed to create source\n");
 			goto cleanup_pipeline;
 		}
 	}
@@ -616,25 +616,25 @@ wfd_compositor_create(struct wl_display *display,
 
 	ec->udev = udev_new();
 	if (ec->udev == NULL) {
-		fprintf(stderr, "failed to initialize udev context\n");
+		weston_log("failed to initialize udev context\n");
 		return NULL;
 	}
 
 	ec->dev = wfdCreateDevice(WFD_DEFAULT_DEVICE_ID, NULL);
 	if (ec->dev == WFD_INVALID_HANDLE) {
-		fprintf(stderr, "failed to create wfd device\n");
+		weston_log("failed to create wfd device\n");
 		return NULL;
 	}
 
 	ec->event = wfdCreateEvent(ec->dev, NULL);
 	if (ec->event == WFD_INVALID_HANDLE) {
-		fprintf(stderr, "failed to create wfd event\n");
+		weston_log("failed to create wfd event\n");
 		return NULL;
 	}
 
 	ec->base.wl_display = display;
 	if (init_egl(ec) < 0) {
-		fprintf(stderr, "failed to initialize egl\n");
+		weston_log("failed to initialize egl\n");
 		return NULL;
 	}
 
@@ -649,7 +649,7 @@ wfd_compositor_create(struct wl_display *display,
 		return NULL;
 
 	if (create_outputs(ec, connector) < 0) {
-		fprintf(stderr, "failed to create outputs\n");
+		weston_log("failed to create outputs\n");
 		return NULL;
 	}
 
diff --git a/src/compositor-wayland.c b/src/compositor-wayland.c
index bbacea4..8e71dd7 100644
--- a/src/compositor-wayland.c
+++ b/src/compositor-wayland.c
@@ -41,6 +41,7 @@
 #include <EGL/eglext.h>
 
 #include "compositor.h"
+#include "log.h"
 
 struct wayland_compositor {
 	struct weston_compositor	 base;
@@ -216,7 +217,7 @@ create_border(struct wayland_compositor *c)
 
 	image = load_image(DATADIR "/weston/border.png");
 	if (!image) {
-		fprintf(stderr, "could'nt load border image\n");
+		weston_log("could'nt load border image\n");
 		return;
 	}
 
@@ -282,35 +283,35 @@ wayland_compositor_init_egl(struct wayland_compositor *c)
 
 	c->base.display = eglGetDisplay(c->parent.display);
 	if (c->base.display == NULL) {
-		fprintf(stderr, "failed to create display\n");
+		weston_log("failed to create display\n");
 		return -1;
 	}
 
 	if (!eglInitialize(c->base.display, &major, &minor)) {
-		fprintf(stderr, "failed to initialize display\n");
+		weston_log("failed to initialize display\n");
 		return -1;
 	}
 
 	if (!eglBindAPI(EGL_OPENGL_ES_API)) {
-		fprintf(stderr, "failed to bind EGL_OPENGL_ES_API\n");
+		weston_log("failed to bind EGL_OPENGL_ES_API\n");
 		return -1;
 	}
    	if (!eglChooseConfig(c->base.display, config_attribs,
 			     &c->base.config, 1, &n) || n == 0) {
-		fprintf(stderr, "failed to choose config: %d\n", n);
+		weston_log("failed to choose config: %d\n", n);
 		return -1;
 	}
 
 	c->base.context = eglCreateContext(c->base.display, c->base.config,
 					   EGL_NO_CONTEXT, context_attribs);
 	if (c->base.context == NULL) {
-		fprintf(stderr, "failed to create context\n");
+		weston_log("failed to create context\n");
 		return -1;
 	}
 
 	c->dummy_pixmap = wl_egl_pixmap_create(10, 10, 0);
 	if (!c->dummy_pixmap) {
-		fprintf(stderr, "failure to create dummy_pixmap\n");
+		weston_log("failure to create dummy_pixmap\n");
 		return -1;
 	}
 
@@ -319,7 +320,7 @@ wayland_compositor_init_egl(struct wayland_compositor *c)
 				       c->dummy_pixmap, NULL);
 	if (!eglMakeCurrent(c->base.display, c->dummy_egl_surface,
 			    c->dummy_egl_surface, c->base.context)) {
-		fprintf(stderr, "failed to make context current\n");
+		weston_log("failed to make context current\n");
 		return -1;
 	}
 
@@ -351,7 +352,7 @@ wayland_output_repaint(struct weston_output *output_base,
 
 	if (!eglMakeCurrent(compositor->base.display, output->egl_surface,
 			    output->egl_surface, compositor->base.context)) {
-		fprintf(stderr, "failed to make current\n");
+		weston_log("failed to make current\n");
 		return;
 	}
 
@@ -421,7 +422,7 @@ wayland_compositor_create_output(struct wayland_compositor *c,
 				     width + c->border.left + c->border.right,
 				     height + c->border.top + c->border.bottom);
 	if (!output->parent.egl_window) {
-		fprintf(stderr, "failure to create wl_egl_window\n");
+		weston_log("failure to create wl_egl_window\n");
 		goto cleanup_output;
 	}
 
@@ -429,13 +430,13 @@ wayland_compositor_create_output(struct wayland_compositor *c,
 		eglCreateWindowSurface(c->base.display, c->base.config,
 				       output->parent.egl_window, NULL);
 	if (!output->egl_surface) {
-		fprintf(stderr, "failed to create window surface\n");
+		weston_log("failed to create window surface\n");
 		goto cleanup_window;
 	}
 
 	if (!eglMakeCurrent(c->base.display, output->egl_surface,
 			    output->egl_surface, c->base.context)) {
-		fprintf(stderr, "failed to make surface current\n");
+		weston_log("failed to make surface current\n");
 		goto cleanup_surface;
 		return -1;
 	}
@@ -736,7 +737,7 @@ wayland_compositor_create(struct wl_display *display,
 	c->parent.display = wl_display_connect(display_name);
 
 	if (c->parent.display == NULL) {
-		fprintf(stderr, "failed to create display: %m\n");
+		weston_log("failed to create display: %m\n");
 		return NULL;
 	}
 
diff --git a/src/compositor-x11.c b/src/compositor-x11.c
index 7452c1c..b8cbaad 100644
--- a/src/compositor-x11.c
+++ b/src/compositor-x11.c
@@ -26,7 +26,6 @@
 #endif
 
 #include <stddef.h>
-#include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 #include <fcntl.h>
@@ -44,6 +43,7 @@
 
 #include "compositor.h"
 #include "../shared/config-parser.h"
+#include "log.h"
 
 struct x11_compositor {
 	struct weston_compositor	 base;
@@ -141,29 +141,29 @@ x11_compositor_init_egl(struct x11_compositor *c)
 
 	c->base.display = eglGetDisplay(c->dpy);
 	if (c->base.display == NULL) {
-		fprintf(stderr, "failed to create display\n");
+		weston_log("failed to create display\n");
 		return -1;
 	}
 
 	if (!eglInitialize(c->base.display, &major, &minor)) {
-		fprintf(stderr, "failed to initialize display\n");
+		weston_log("failed to initialize display\n");
 		return -1;
 	}
 
 	if (!eglBindAPI(EGL_OPENGL_ES_API)) {
-		fprintf(stderr, "failed to bind EGL_OPENGL_ES_API\n");
+		weston_log("failed to bind EGL_OPENGL_ES_API\n");
 		return -1;
 	}
    	if (!eglChooseConfig(c->base.display, config_attribs,
 			     &c->base.config, 1, &n) || n == 0) {
-		fprintf(stderr, "failed to choose config: %d\n", n);
+		weston_log("failed to choose config: %d\n", n);
 		return -1;
 	}
 
 	c->base.context = eglCreateContext(c->base.display, c->base.config,
 					   EGL_NO_CONTEXT, context_attribs);
 	if (c->base.context == NULL) {
-		fprintf(stderr, "failed to create context\n");
+		weston_log("failed to create context\n");
 		return -1;
 	}
 
@@ -171,13 +171,13 @@ x11_compositor_init_egl(struct x11_compositor *c)
 						   c->base.config,
 						   pbuffer_attribs);
 	if (c->dummy_pbuffer == NULL) {
-		fprintf(stderr, "failed to create dummy pbuffer\n");
+		weston_log("failed to create dummy pbuffer\n");
 		return -1;
 	}
 
 	if (!eglMakeCurrent(c->base.display, c->dummy_pbuffer,
 			    c->dummy_pbuffer, c->base.context)) {
-		fprintf(stderr, "failed to make context current\n");
+		weston_log("failed to make context current\n");
 		return -1;
 	}
 
@@ -206,7 +206,7 @@ x11_output_repaint(struct weston_output *output_base,
 
 	if (!eglMakeCurrent(compositor->base.display, output->egl_surface,
 			    output->egl_surface, compositor->base.context)) {
-		fprintf(stderr, "failed to make current\n");
+		weston_log("failed to make current\n");
 		return;
 	}
 
@@ -441,12 +441,12 @@ x11_compositor_create_output(struct x11_compositor *c, int x, int y,
 		eglCreateWindowSurface(c->base.display, c->base.config,
 				       output->window, NULL);
 	if (!output->egl_surface) {
-		fprintf(stderr, "failed to create window surface\n");
+		weston_log("failed to create window surface\n");
 		return -1;
 	}
 	if (!eglMakeCurrent(c->base.display, output->egl_surface,
 			    output->egl_surface, c->base.context)) {
-		fprintf(stderr, "failed to make surface current\n");
+		weston_log("failed to make surface current\n");
 		return -1;
 	}
 
diff --git a/src/compositor.c b/src/compositor.c
index fa17363..b1b819c 100644
--- a/src/compositor.c
+++ b/src/compositor.c
@@ -70,7 +70,7 @@ sigchld_handler(int signal_number, void *data)
 	}
 
 	if (&p->link == &child_process_list) {
-		fprintf(stderr, "unknown child process exited\n");
+		weston_log("unknown child process exited\n");
 		return 1;
 	}
 
@@ -113,7 +113,7 @@ child_client_exec(int sockfd, const char *path)
 	 * non-CLOEXEC fd to pass through exec. */
 	clientfd = dup(sockfd);
 	if (clientfd == -1) {
-		fprintf(stderr, "compositor: dup failed: %m\n");
+		weston_log("compositor: dup failed: %m\n");
 		return;
 	}
 
@@ -121,7 +121,7 @@ child_client_exec(int sockfd, const char *path)
 	setenv("WAYLAND_SOCKET", s, 1);
 
 	if (execl(path, path, NULL) < 0)
-		fprintf(stderr, "compositor: executing '%s' failed: %m\n",
+		weston_log("compositor: executing '%s' failed: %m\n",
 			path);
 }
 
@@ -136,7 +136,7 @@ weston_client_launch(struct weston_compositor *compositor,
 	struct wl_client *client;
 
 	if (socketpair(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0, sv) < 0) {
-		fprintf(stderr, "weston_client_launch: "
+		weston_log("weston_client_launch: "
 			"socketpair failed while launching '%s': %m\n",
 			path);
 		return NULL;
@@ -146,7 +146,7 @@ weston_client_launch(struct weston_compositor *compositor,
 	if (pid == -1) {
 		close(sv[0]);
 		close(sv[1]);
-		fprintf(stderr,  "weston_client_launch: "
+		weston_log("weston_client_launch: "
 			"fork failed while launching '%s': %m\n", path);
 		return NULL;
 	}
@@ -161,7 +161,7 @@ weston_client_launch(struct weston_compositor *compositor,
 	client = wl_client_create(compositor->wl_display, sv[0]);
 	if (!client) {
 		close(sv[0]);
-		fprintf(stderr, "weston_client_launch: "
+		weston_log("weston_client_launch: "
 			"wl_client_create failed while launching '%s'.\n",
 			path);
 		return NULL;
@@ -281,7 +281,7 @@ surface_to_global_float(struct weston_surface *surface,
 		weston_matrix_transform(&surface->transform.matrix, &v);
 
 		if (fabsf(v.f[3]) < 1e-6) {
-			fprintf(stderr, "warning: numerical instability in "
+			weston_log("warning: numerical instability in "
 				"weston_surface_to_global(), divisor = %g\n",
 				v.f[3]);
 			*x = 0;
@@ -389,7 +389,7 @@ weston_surface_update_transform_enable(struct weston_surface *surface)
 
 	if (weston_matrix_invert(inverse, matrix) < 0) {
 		/* Oops, bad total transformation, not invertible */
-		fprintf(stderr, "error: weston_surface %p"
+		weston_log("error: weston_surface %p"
 			" transformation not invertible.\n", surface);
 		return -1;
 	}
@@ -484,7 +484,7 @@ surface_from_global_float(struct weston_surface *surface,
 		weston_matrix_transform(&surface->transform.inverse, &v);
 
 		if (fabsf(v.f[3]) < 1e-6) {
-			fprintf(stderr, "warning: numerical instability in "
+			weston_log("warning: numerical instability in "
 				"weston_surface_from_global(), divisor = %g\n",
 				v.f[3]);
 			*sx = 0;
@@ -1907,7 +1907,7 @@ touch_set_focus(struct weston_seat *ws, struct wl_surface *surface)
 			find_resource_for_client(&seat->touch->resource_list,
 						 surface->resource.client);
 		if (!resource) {
-			fprintf(stderr, "couldn't find resource\n");
+			weston_log("couldn't find resource\n");
 			return;
 		}
 
@@ -2388,7 +2388,7 @@ compile_shader(GLenum type, const char *source)
 	glGetShaderiv(s, GL_COMPILE_STATUS, &status);
 	if (!status) {
 		glGetShaderInfoLog(s, sizeof msg, NULL, msg);
-		fprintf(stderr, "shader info: %s\n", msg);
+		weston_log("shader info: %s\n", msg);
 		return GL_NONE;
 	}
 
@@ -2417,7 +2417,7 @@ weston_shader_init(struct weston_shader *shader,
 	glGetProgramiv(shader->program, GL_LINK_STATUS, &status);
 	if (!status) {
 		glGetProgramInfoLog(shader->program, sizeof msg, NULL, msg);
-		fprintf(stderr, "link info: %s\n", msg);
+		weston_log("link info: %s\n", msg);
 		return -1;
 	}
 
@@ -2648,13 +2648,12 @@ weston_compositor_init(struct weston_compositor *ec, struct wl_display *display)
 
 	extensions = (const char *) glGetString(GL_EXTENSIONS);
 	if (!extensions) {
-		fprintf(stderr, "Retrieving GL extension string failed.\n");
+		weston_log("Retrieving GL extension string failed.\n");
 		return -1;
 	}
 
 	if (!strstr(extensions, "GL_EXT_texture_format_BGRA8888")) {
-		fprintf(stderr,
-			"GL_EXT_texture_format_BGRA8888 not available\n");
+		weston_log("GL_EXT_texture_format_BGRA8888 not available\n");
 		return -1;
 	}
 
@@ -2669,7 +2668,7 @@ weston_compositor_init(struct weston_compositor *ec, struct wl_display *display)
 	extensions =
 		(const char *) eglQueryString(ec->display, EGL_EXTENSIONS);
 	if (!extensions) {
-		fprintf(stderr, "Retrieving EGL extension string failed.\n");
+		weston_log("Retrieving EGL extension string failed.\n");
 		return -1;
 	}
 
@@ -2744,7 +2743,7 @@ static int weston_compositor_xkb_init(struct weston_compositor *ec,
 {
 	ec->xkb_info.context = xkb_context_new(0);
 	if (ec->xkb_info.context == NULL) {
-		fprintf(stderr, "failed to create XKB context\n");
+		weston_log("failed to create XKB context\n");
 		return -1;
 	}
 
@@ -2759,13 +2758,13 @@ static int weston_compositor_xkb_init(struct weston_compositor *ec,
 	ec->xkb_info.keymap = xkb_map_new_from_names(ec->xkb_info.context,
 	                                             &ec->xkb_info.names, 0);
 	if (ec->xkb_info.keymap == NULL) {
-		fprintf(stderr, "failed to compile XKB keymap\n");
+		weston_log("failed to compile XKB keymap\n");
 		return -1;
 	}
 
 	ec->xkb_info.state = xkb_state_new(ec->xkb_info.keymap);
 	if (ec->xkb_info.state == NULL) {
-		fprintf(stderr, "failed to initialise XKB state\n");
+		weston_log("failed to initialise XKB state\n");
 		return -1;
 	}
 
@@ -2789,7 +2788,7 @@ static int on_term_signal(int signal_number, void *data)
 {
 	struct wl_display *display = data;
 
-	fprintf(stderr, "caught signal %d\n", signal_number);
+	weston_log("caught signal %d\n", signal_number);
 	wl_display_terminate(display);
 
 	return 1;
@@ -2802,12 +2801,12 @@ on_segv_signal(int s, siginfo_t *siginfo, void *context)
 	int i, count;
 	Dl_info info;
 
-	fprintf(stderr, "caught segv\n");
+	weston_log("caught segv\n");
 
 	count = backtrace(buffer, ARRAY_LENGTH(buffer));
 	for (i = 0; i < count; i++) {
 		dladdr(buffer[i], &info);
-		fprintf(stderr, "  [%016lx]  %s  (%s)\n",
+		weston_log("  [%016lx]  %s  (%s)\n",
 			(long) buffer[i],
 			info.dli_sname ? info.dli_sname : "--",
 			info.dli_fname);
@@ -2830,15 +2829,13 @@ load_module(const char *name, const char *entrypoint, void **handle)
 
 	module = dlopen(path, RTLD_LAZY);
 	if (!module) {
-		fprintf(stderr,
-			"failed to load module '%s': %s\n", path, dlerror());
+		weston_log("failed to load module '%s': %s\n", path, dlerror());
 		return NULL;
 	}
 
 	init = dlsym(module, entrypoint);
 	if (!init) {
-		fprintf(stderr,
-			"failed to lookup init function in '%s': %s\n",
+		weston_log("failed to lookup init function in '%s': %s\n",
 			path, dlerror());
 		return NULL;
 	}
@@ -2945,17 +2942,17 @@ int main(int argc, char *argv[])
 
 	ec = backend_init(display, argc, argv);
 	if (ec == NULL) {
-		fprintf(stderr, "failed to create compositor\n");
+		weston_log("failed to create compositor\n");
 		exit(EXIT_FAILURE);
 	}
 
 	for (i = 1; argv[i]; i++)
-		fprintf(stderr, "unhandled option: %s\n", argv[i]);
+		weston_log("unhandled option: %s\n", argv[i]);
 	if (argv[1])
 		exit(EXIT_FAILURE);
 
 	if (weston_compositor_xkb_init(ec, &xkb_names) == -1) {
-		fprintf(stderr, "failed to initialise keyboard support\n");
+		weston_log("failed to initialise keyboard support\n");
 		exit(EXIT_FAILURE);
 	}
 
@@ -2984,7 +2981,7 @@ int main(int argc, char *argv[])
 		exit(EXIT_FAILURE);
 
 	if (wl_display_add_socket(display, socket_name)) {
-		fprintf(stderr, "failed to add socket: %m\n");
+		weston_log("failed to add socket: %m\n");
 		exit(EXIT_FAILURE);
 	}
 
diff --git a/src/evdev.c b/src/evdev.c
index 73b012b..7de051d 100644
--- a/src/evdev.c
+++ b/src/evdev.c
@@ -20,7 +20,6 @@
  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
 
-#include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 #include <linux/input.h>
@@ -32,6 +31,7 @@
 #include "evdev.h"
 #include "evdev-private.h"
 #include "launcher-util.h"
+#include "log.h"
 
 static inline void
 evdev_process_key(struct evdev_input_device *device,
@@ -426,7 +426,7 @@ evdev_input_device_create(struct evdev_seat *master,
 	if (device->is_mt) {
 		device->mtdev = mtdev_new_open(device->fd);
 		if (!device->mtdev)
-			fprintf(stderr, "mtdev failed to open for %s\n", path);
+			weston_log("mtdev failed to open for %s\n", path);
 	}
 
 	device->source = wl_event_loop_add_fd(ec->input_loop, device->fd,
@@ -504,7 +504,7 @@ evdev_notify_keyboard_focus(struct evdev_seat *seat)
 		ret = ioctl(device->fd,
 			    EVIOCGKEY(sizeof evdev_keys), evdev_keys);
 		if (ret < 0) {
-			fprintf(stderr, "failed to get keys for device %s\n",
+			weston_log("failed to get keys for device %s\n",
 				device->devnode);
 			continue;
 		}
@@ -557,7 +557,7 @@ evdev_add_devices(struct udev *udev, struct weston_seat *seat_base)
 	evdev_notify_keyboard_focus(seat);
 
 	if (wl_list_empty(&seat->devices_list)) {
-		fprintf(stderr,
+		weston_log(
 			"warning: no input devices on entering Weston. "
 			"Possible causes:\n"
 			"\t- no permissions to read /dev/input/event*\n"
@@ -613,7 +613,7 @@ evdev_enable_udev_monitor(struct udev *udev, struct weston_seat *seat_base)
 
 	master->udev_monitor = udev_monitor_new_from_netlink(udev, "udev");
 	if (!master->udev_monitor) {
-		fprintf(stderr, "udev: failed to create the udev monitor\n");
+		weston_log("udev: failed to create the udev monitor\n");
 		return 0;
 	}
 
@@ -621,7 +621,7 @@ evdev_enable_udev_monitor(struct udev *udev, struct weston_seat *seat_base)
 			"input", NULL);
 
 	if (udev_monitor_enable_receiving(master->udev_monitor)) {
-		fprintf(stderr, "udev: failed to bind the udev monitor\n");
+		weston_log("udev: failed to bind the udev monitor\n");
 		udev_monitor_unref(master->udev_monitor);
 		return 0;
 	}
diff --git a/src/shell.c b/src/shell.c
index dc4fa47..84cda51 100644
--- a/src/shell.c
+++ b/src/shell.c
@@ -36,6 +36,7 @@
 #include "compositor.h"
 #include "desktop-shell-server-protocol.h"
 #include "../shared/config-parser.h"
+#include "log.h"
 
 enum animation_type {
 	ANIMATION_NONE,
@@ -930,7 +931,7 @@ create_black_surface(struct weston_compositor *ec,
 
 	surface = weston_surface_create(ec);
 	if (surface == NULL) {
-		fprintf(stderr, "no memory\n");
+		weston_log("no memory\n");
 		return NULL;
 	}
 
@@ -1271,13 +1272,13 @@ create_shell_surface(void *shell, struct weston_surface *surface,
 	struct shell_surface *shsurf;
 
 	if (surface->configure) {
-		fprintf(stderr, "surface->configure already set\n");
+		weston_log("surface->configure already set\n");
 		return NULL;
 	}
 
 	shsurf = calloc(1, sizeof *shsurf);
 	if (!shsurf) {
-		fprintf(stderr, "no memory to allocate shell surface\n");
+		weston_log("no memory to allocate shell surface\n");
 		return NULL;
 	}
 
@@ -1373,7 +1374,7 @@ launch_screensaver(struct desktop_shell *shell)
 		return;
 
 	if (shell->screensaver.process.pid != 0) {
-		fprintf(stderr, "old screensaver still running\n");
+		weston_log("old screensaver still running\n");
 		return;
 	}
 
@@ -1456,7 +1457,7 @@ handle_lock_surface_destroy(struct wl_listener *listener, void *data)
 	struct desktop_shell *shell =
 	    container_of(listener, struct desktop_shell, lock_surface_listener);
 
-	fprintf(stderr, "lock surface gone\n");
+	weston_log("lock surface gone\n");
 	shell->lock_surface = NULL;
 }
 
@@ -2264,11 +2265,11 @@ desktop_shell_sigchld(struct weston_process *process, int status)
 
 	shell->child.deathcount++;
 	if (shell->child.deathcount > 5) {
-		fprintf(stderr, "weston-desktop-shell died, giving up.\n");
+		weston_log("weston-desktop-shell died, giving up.\n");
 		return;
 	}
 
-	fprintf(stderr, "weston-desktop-shell died, respawning...\n");
+	weston_log("weston-desktop-shell died, respawning...\n");
 	launch_desktop_shell_process(shell);
 }
 
diff --git a/src/tablet-shell.c b/src/tablet-shell.c
index cf9ddf6..7ef0825 100644
--- a/src/tablet-shell.c
+++ b/src/tablet-shell.c
@@ -23,12 +23,12 @@
 #include <sys/wait.h>
 #include <unistd.h>
 #include <stdlib.h>
-#include <stdio.h>
 #include <string.h>
 #include <linux/input.h>
 
 #include "compositor.h"
 #include "tablet-shell-server-protocol.h"
+#include "log.h"
 
 /*
  * TODO: Don't fade back from black until we've received a lockscreen
@@ -105,8 +105,7 @@ tablet_shell_sigchld(struct weston_process *process, int status)
 
 	shell->process.pid = 0;
 
-	fprintf(stderr,
-		"weston-tablet-shell crashed, exit code %d\n", status);
+	weston_log("weston-tablet-shell crashed, exit code %d\n", status);
 }
 
 static void
@@ -116,7 +115,7 @@ tablet_shell_set_state(struct tablet_shell *shell, int state)
 		"STARTING", "LOCKED", "HOME", "SWITCHER", "TASK"
 	};
 
-	fprintf(stderr, "switching to state %s (from %s)\n",
+	weston_log("switching to state %s (from %s)\n",
 		states[state], states[shell->state]);
 	shell->previous_state = shell->state;
 	shell->state = state;
@@ -268,7 +267,7 @@ tablet_shell_switch_to(struct tablet_shell *shell,
 				      minimize_zoom_done, shell);
 		}
 	} else {
-		fprintf(stderr, "switch to %p\n", surface);
+		weston_log("switch to %p\n", surface);
 		weston_surface_activate(surface, seat);
 		tablet_shell_set_state(shell, STATE_TASK);
 		weston_zoom_run(surface, 0.3, 1.0, NULL, NULL);
@@ -362,7 +361,7 @@ tablet_shell_create_client(struct wl_client *client,
 	tablet_client->surface = NULL;
 	shell->current_client = tablet_client;
 
-	fprintf(stderr, "created client %p, id %d, name %s, fd %d\n",
+	weston_log("created client %p, id %d, name %s, fd %d\n",
 		tablet_client->client, id, name, fd);
 }
 
diff --git a/src/tty.c b/src/tty.c
index 78d5ba5..a8b2aed 100644
--- a/src/tty.c
+++ b/src/tty.c
@@ -35,6 +35,7 @@
 #include <sys/stat.h>
 
 #include "compositor.h"
+#include "log.h"
 
 /* Introduced in 2.6.38 */
 #ifndef K_OFF
@@ -91,19 +92,19 @@ try_open_vt(struct tty *tty)
 
 	tty0 = open("/dev/tty0", O_WRONLY | O_CLOEXEC);
 	if (tty0 < 0) {
-		fprintf(stderr, "could not open tty0: %m\n");
+		weston_log("could not open tty0: %m\n");
 		return -1;
 	}
 
 	if (ioctl(tty0, VT_OPENQRY, &tty->vt) < 0 || tty->vt == -1) {
-		fprintf(stderr, "could not open tty0: %m\n");
+		weston_log("could not open tty0: %m\n");
 		close(tty0);
 		return -1;
 	}
 
 	close(tty0);
 	snprintf(filename, sizeof filename, "/dev/tty%d", tty->vt);
-	fprintf(stderr, "compositor: using new vt %s\n", filename);
+	weston_log("compositor: using new vt %s\n", filename);
 	fd = open(filename, O_RDWR | O_NOCTTY | O_CLOEXEC);
 	if (fd < 0)
 		return fd;
@@ -144,7 +145,7 @@ tty_create(struct weston_compositor *compositor, tty_vt_func_t vt_func,
 
 	if (tty_nr > 0) {
 		snprintf(filename, sizeof filename, "/dev/tty%d", tty_nr);
-		fprintf(stderr, "compositor: using %s\n", filename);
+		weston_log("compositor: using %s\n", filename);
 		tty->fd = open(filename, O_RDWR | O_NOCTTY | O_CLOEXEC);
 		tty->vt = tty_nr;
 	} else if (fstat(tty->fd, &buf) == 0 &&
@@ -160,7 +161,7 @@ tty_create(struct weston_compositor *compositor, tty_vt_func_t vt_func,
 	}
 
 	if (tty->fd <= 0) {
-		fprintf(stderr, "failed to open tty: %m\n");
+		weston_log("failed to open tty: %m\n");
 		free(tty);
 		return NULL;
 	}
@@ -173,13 +174,13 @@ tty_create(struct weston_compositor *compositor, tty_vt_func_t vt_func,
 	if (tty->starting_vt != tty->vt) {
 		if (ioctl(tty->fd, VT_ACTIVATE, tty->vt) < 0 ||
 		    ioctl(tty->fd, VT_WAITACTIVE, tty->vt) < 0) {
-			fprintf(stderr, "failed to swtich to new vt\n");
+			weston_log("failed to swtich to new vt\n");
 			return NULL;
 		}
 	}
 
 	if (tcgetattr(tty->fd, &tty->terminal_attributes) < 0) {
-		fprintf(stderr, "could not get terminal attributes: %m\n");
+		weston_log("could not get terminal attributes: %m\n");
 		goto err;
 	}
 
@@ -191,7 +192,7 @@ tty_create(struct weston_compositor *compositor, tty_vt_func_t vt_func,
 	raw_attributes.c_oflag |= OPOST | OCRNL;
 
 	if (tcsetattr(tty->fd, TCSANOW, &raw_attributes) < 0)
-		fprintf(stderr, "could not put terminal into raw mode: %m\n");
+		weston_log("could not put terminal into raw mode: %m\n");
 
 	loop = wl_display_get_event_loop(compositor->wl_display);
 
@@ -210,13 +211,13 @@ tty_create(struct weston_compositor *compositor, tty_vt_func_t vt_func,
 	}
 
 	if (ret) {
-		fprintf(stderr, "failed to set K_OFF keyboard mode on tty: %m\n");
+		weston_log("failed to set K_OFF keyboard mode on tty: %m\n");
 		goto err_attr;
 	}
 
 	ret = ioctl(tty->fd, KDSETMODE, KD_GRAPHICS);
 	if (ret) {
-		fprintf(stderr, "failed to set KD_GRAPHICS mode on tty: %m\n");
+		weston_log("failed to set KD_GRAPHICS mode on tty: %m\n");
 		goto err_kdkbmode;
 	}
 
@@ -225,7 +226,7 @@ tty_create(struct weston_compositor *compositor, tty_vt_func_t vt_func,
 	mode.relsig = SIGUSR1;
 	mode.acqsig = SIGUSR1;
 	if (ioctl(tty->fd, VT_SETMODE, &mode) < 0) {
-		fprintf(stderr, "failed to take control of vt handling\n");
+		weston_log("failed to take control of vt handling\n");
 		goto err_kdmode;
 	}
 
@@ -265,19 +266,17 @@ tty_destroy(struct tty *tty)
 		wl_event_source_remove(tty->input_source);
 
 	if (ioctl(tty->fd, KDSKBMODE, tty->kb_mode))
-		fprintf(stderr, "failed to restore keyboard mode: %m\n");
+		weston_log("failed to restore keyboard mode: %m\n");
 
 	if (ioctl(tty->fd, KDSETMODE, KD_TEXT))
-		fprintf(stderr,
-			"failed to set KD_TEXT mode on tty: %m\n");
+		weston_log("failed to set KD_TEXT mode on tty: %m\n");
 
 	if (tcsetattr(tty->fd, TCSANOW, &tty->terminal_attributes) < 0)
-		fprintf(stderr,
-			"could not restore terminal to canonical mode\n");
+		weston_log("could not restore terminal to canonical mode\n");
 
 	mode.mode = VT_AUTO;
 	if (ioctl(tty->fd, VT_SETMODE, &mode) < 0)
-		fprintf(stderr, "could not reset vt handling\n");
+		weston_log("could not reset vt handling\n");
 
 	if (tty->has_vt && tty->vt != tty->starting_vt) {
 		ioctl(tty->fd, VT_ACTIVATE, tty->starting_vt);
diff --git a/src/xwayland/launcher.c b/src/xwayland/launcher.c
index d8880bd..0184c08 100644
--- a/src/xwayland/launcher.c
+++ b/src/xwayland/launcher.c
@@ -34,6 +34,7 @@
 
 #include "xwayland.h"
 #include "xserver-server-protocol.h"
+#include "../log.h"
 
 
 static int
@@ -44,7 +45,7 @@ weston_xserver_handle_event(int listen_fd, uint32_t mask, void *data)
 	int sv[2], client_fd;
 
 	if (socketpair(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0, sv) < 0) {
-		fprintf(stderr, "socketpair failed\n");
+		weston_log("socketpair failed\n");
 		return 1;
 	}
 
@@ -71,11 +72,11 @@ weston_xserver_handle_event(int listen_fd, uint32_t mask, void *data)
 			  "-nolisten", "all",
 			  "-terminate",
 			  NULL) < 0)
-			fprintf(stderr, "exec failed: %m\n");
+			weston_log("exec failed: %m\n");
 		exit(-1);
 
 	default:
-		fprintf(stderr, "forked X server, pid %d\n", mxs->process.pid);
+		weston_log("forked X server, pid %d\n", mxs->process.pid);
 
 		close(sv[1]);
 		mxs->client = wl_client_create(mxs->wl_display, sv[0]);
@@ -87,7 +88,7 @@ weston_xserver_handle_event(int listen_fd, uint32_t mask, void *data)
 		break;
 
 	case -1:
-		fprintf(stderr, "failed to fork\n");
+		weston_log( "failed to fork\n");
 		break;
 	}
 
@@ -135,14 +136,14 @@ weston_xserver_cleanup(struct weston_process *process, int status)
 				     weston_xserver_handle_event, mxs);
 
 	if (mxs->wm) {
-		fprintf(stderr, "xserver exited, code %d\n", status);
+		weston_log("xserver exited, code %d\n", status);
 		weston_wm_destroy(mxs->wm);
 		mxs->wm = NULL;
 	} else {
 		/* If the X server crashes before it binds to the
 		 * xserver interface, shut down and don't try
 		 * again. */
-		fprintf(stderr, "xserver crashing too fast: %d\n", status);
+		weston_log("xserver crashing too fast: %d\n", status);
 		weston_xserver_shutdown(mxs);
 	}
 }
@@ -164,7 +165,7 @@ bind_xserver(struct wl_client *client,
 
 	wxs->wm = weston_wm_create(wxs);
 	if (wxs->wm == NULL) {
-		fprintf(stderr, "failed to create wm\n");
+		weston_log("failed to create wm\n");
 	}
 
 	xserver_send_listen_socket(wxs->resource, wxs->abstract_fd);
@@ -187,7 +188,7 @@ bind_to_abstract_socket(int display)
 			     "%c/tmp/.X11-unix/X%d", 0, display);
 	size = offsetof(struct sockaddr_un, sun_path) + name_size;
 	if (bind(fd, (struct sockaddr *) &addr, size) < 0) {
-		fprintf(stderr, "failed to bind to @%s: %s\n",
+		weston_log("failed to bind to @%s: %s\n",
 			addr.sun_path + 1, strerror(errno));
 		close(fd);
 		return -1;
@@ -218,7 +219,7 @@ bind_to_unix_socket(int display)
 	size = offsetof(struct sockaddr_un, sun_path) + name_size;
 	unlink(addr.sun_path);
 	if (bind(fd, (struct sockaddr *) &addr, size) < 0) {
-		fprintf(stderr, "failed to bind to %s (%s)\n",
+		weston_log("failed to bind to %s (%s)\n",
 			addr.sun_path, strerror(errno));
 		close(fd);
 		return -1;
@@ -245,7 +246,7 @@ create_lockfile(int display, char *lockfile, size_t lsize)
 	if (fd < 0 && errno == EEXIST) {
 		fd = open(lockfile, O_CLOEXEC, O_RDONLY);
 		if (fd < 0 || read(fd, pid, 11) != 11) {
-			fprintf(stderr, "can't read lock file %s: %s\n",
+			weston_log("can't read lock file %s: %s\n",
 				lockfile, strerror(errno));
 			errno = EEXIST;
 			return -1;
@@ -253,7 +254,7 @@ create_lockfile(int display, char *lockfile, size_t lsize)
 
 		other = strtol(pid, &end, 0);
 		if (end != pid + 10) {
-			fprintf(stderr, "can't parse lock file %s\n",
+			weston_log("can't parse lock file %s\n",
 				lockfile);
 			close(fd);
 			errno = EEXIST;
@@ -262,8 +263,7 @@ create_lockfile(int display, char *lockfile, size_t lsize)
 
 		if (kill(other, 0) < 0 && errno == ESRCH) {
 			/* stale lock file; unlink and try again */
-			fprintf(stderr,
-				"unlinking stale lock file %s\n", lockfile);
+			weston_log("unlinking stale lock file %s\n", lockfile);
 			close(fd);
 			if (unlink(lockfile))
 				/* If we fail to unlink, return EEXIST
@@ -277,7 +277,7 @@ create_lockfile(int display, char *lockfile, size_t lsize)
 		errno = EEXIST;
 		return -1;
 	} else if (fd < 0) {
-		fprintf(stderr, "failed to create lock file %s: %s\n",
+		weston_log("failed to create lock file %s: %s\n",
 			lockfile, strerror(errno));
 		return -1;
 	}
@@ -356,7 +356,7 @@ weston_xserver_init(struct weston_compositor *compositor)
 	}
 
 	snprintf(display_name, sizeof display_name, ":%d", mxs->display);
-	fprintf(stderr, "xserver listening on display %s\n", display_name);
+	weston_log("xserver listening on display %s\n", display_name);
 	setenv("DISPLAY", display_name, 1);
 
 	mxs->loop = wl_display_get_event_loop(display);
diff --git a/src/xwayland/selection.c b/src/xwayland/selection.c
index d0105dd..fe7ab92 100644
--- a/src/xwayland/selection.c
+++ b/src/xwayland/selection.c
@@ -23,12 +23,12 @@
 #define _GNU_SOURCE
 
 #include <stdlib.h>
-#include <stdio.h>
 #include <string.h>
 #include <unistd.h>
 #include <fcntl.h>
 
 #include "xwayland.h"
+#include "../log.h"
 
 static int
 weston_wm_write_property(int fd, uint32_t mask, void *data)
@@ -46,11 +46,11 @@ weston_wm_write_property(int fd, uint32_t mask, void *data)
 		free(wm->property_reply);
 		wl_event_source_remove(wm->property_source);
 		close(fd);
-		fprintf(stderr, "write error to target fd: %m\n");
+		weston_log("write error to target fd: %m\n");
 		return 1;
 	}
 
-	fprintf(stderr, "wrote %d (chunk size %d) of %d bytes\n",
+	weston_log("wrote %d (chunk size %d) of %d bytes\n",
 		wm->property_start + len,
 		len, xcb_get_property_value_length(wm->property_reply));
 
@@ -64,7 +64,7 @@ weston_wm_write_property(int fd, uint32_t mask, void *data)
 					    wm->selection_window,
 					    wm->atom.wl_selection);
 		} else {
-			fprintf(stderr, "transfer complete\n");
+			weston_log("transfer complete\n");
 			close(fd);
 		}
 	}
@@ -100,7 +100,7 @@ weston_wm_get_incr_chunk(struct weston_wm *wm)
 					     wm);
 		wm->property_reply = reply;
 	} else {
-		fprintf(stderr, "transfer complete\n");
+		weston_log("transfer complete\n");
 		close(wm->data_source_fd);
 		free(reply);
 	}
@@ -352,20 +352,20 @@ weston_wm_read_data_source(int fd, uint32_t mask, void *data)
 
 	len = read(fd, p, available);
 	if (len == -1) {
-		fprintf(stderr, "read error from data source: %m\n");
+		weston_log("read error from data source: %m\n");
 		weston_wm_send_selection_notify(wm, XCB_ATOM_NONE);
 		wl_event_source_remove(wm->property_source);
 		close(fd);
 		wl_array_release(&wm->source_data);
 	}
 
-	fprintf(stderr, "read %d (available %d, mask 0x%x) bytes: \"%.*s\"\n",
+	weston_log("read %d (available %d, mask 0x%x) bytes: \"%.*s\"\n",
 		len, available, mask, len, (char *) p);
 
 	wm->source_data.size = current + len;
 	if (wm->source_data.size >= incr_chunk_size) {
 		if (!wm->incr) {
-			fprintf(stderr, "got %zu bytes, starting incr\n",
+			weston_log("got %zu bytes, starting incr\n",
 				wm->source_data.size);
 			wm->incr = 1;
 			xcb_change_property(wm->conn,
@@ -380,19 +380,19 @@ weston_wm_read_data_source(int fd, uint32_t mask, void *data)
 			wl_event_source_remove(wm->property_source);
 			weston_wm_send_selection_notify(wm, wm->selection_request.property);
 		} else if (wm->selection_property_set) {
-			fprintf(stderr, "got %zu bytes, waiting for "
+			weston_log("got %zu bytes, waiting for "
 				"property delete\n", wm->source_data.size);
 
 			wm->flush_property_on_delete = 1;
 			wl_event_source_remove(wm->property_source);
 		} else {
-			fprintf(stderr, "got %zu bytes, "
+			weston_log("got %zu bytes, "
 				"property deleted, seting new property\n",
 				wm->source_data.size);
 			weston_wm_flush_source_data(wm);
 		}
 	} else if (len == 0 && !wm->incr) {
-		fprintf(stderr, "non-incr transfer complete\n");
+		weston_log("non-incr transfer complete\n");
 		/* Non-incr transfer all done. */
 		weston_wm_flush_source_data(wm);
 		weston_wm_send_selection_notify(wm, wm->selection_request.property);
@@ -402,14 +402,14 @@ weston_wm_read_data_source(int fd, uint32_t mask, void *data)
 		wl_array_release(&wm->source_data);
 		wm->selection_request.requestor = XCB_NONE;
 	} else if (len == 0 && wm->incr) {
-		fprintf(stderr, "incr transfer complete\n");
+		weston_log("incr transfer complete\n");
 
 		wm->flush_property_on_delete = 1;
 		if (wm->selection_property_set) {
-			fprintf(stderr, "got %zu bytes, waiting for "
+			weston_log("got %zu bytes, waiting for "
 				"property delete\n", wm->source_data.size);
 		} else {
-			fprintf(stderr, "got %zu bytes, "
+			weston_log("got %zu bytes, "
 				"property deleted, seting new property\n",
 				wm->source_data.size);
 			weston_wm_flush_source_data(wm);
@@ -419,7 +419,7 @@ weston_wm_read_data_source(int fd, uint32_t mask, void *data)
 		wm->data_source_fd = -1;
 		close(fd);
 	} else {
-		fprintf(stderr, "nothing happened, buffered the bytes\n");
+		weston_log("nothing happened, buffered the bytes\n");
 	}
 
 	return 1;
@@ -432,7 +432,7 @@ weston_wm_send_data(struct weston_wm *wm, xcb_atom_t target, const char *mime_ty
 	int p[2];
 
 	if (pipe2(p, O_CLOEXEC | O_NONBLOCK) == -1) {
-		fprintf(stderr, "pipe2 failed: %m\n");
+		weston_log("pipe2 failed: %m\n");
 		weston_wm_send_selection_notify(wm, XCB_ATOM_NONE);
 		return;
 	}
@@ -456,11 +456,11 @@ weston_wm_send_incr_chunk(struct weston_wm *wm)
 {
 	int length;
 
-	fprintf(stderr, "property deleted\n");
+	weston_log("property deleted\n");
 
 	wm->selection_property_set = 0;
 	if (wm->flush_property_on_delete) {
-		fprintf(stderr, "setting new property, %zu bytes\n",
+		weston_log("setting new property, %zu bytes\n",
 			wm->source_data.size);
 		wm->flush_property_on_delete = 0;
 		length = weston_wm_flush_source_data(wm);
@@ -516,11 +516,11 @@ weston_wm_handle_selection_request(struct weston_wm *wm,
 	xcb_selection_request_event_t *selection_request =
 		(xcb_selection_request_event_t *) event;
 
-	fprintf(stderr, "selection request, %s, ",
+	weston_log("selection request, %s, ",
 		get_atom_name(wm->conn, selection_request->selection));
-	fprintf(stderr, "target %s, ",
+	weston_log_continue("target %s, ",
 		get_atom_name(wm->conn, selection_request->target));
-	fprintf(stderr, "property %s\n",
+	weston_log_continue("property %s\n",
 		get_atom_name(wm->conn, selection_request->property));
 
 	wm->selection_request = *selection_request;
@@ -536,7 +536,7 @@ weston_wm_handle_selection_request(struct weston_wm *wm,
 		weston_wm_send_data(wm, wm->atom.utf8_string,
 				  "text/plain;charset=utf-8");
 	} else {
-		fprintf(stderr, "can only handle UTF8_STRING targets...\n");
+		weston_log("can only handle UTF8_STRING targets...\n");
 		weston_wm_send_selection_notify(wm, XCB_ATOM_NONE);
 	}
 }
@@ -548,7 +548,7 @@ weston_wm_handle_xfixes_selection_notify(struct weston_wm *wm,
 	xcb_xfixes_selection_notify_event_t *xfixes_selection_notify =
 		(xcb_xfixes_selection_notify_event_t *) event;
 
-	printf("xfixes selection notify event: owner %d\n",
+	weston_log("xfixes selection notify event: owner %d\n",
 	       xfixes_selection_notify->owner);
 
 	/* We have to use XCB_TIME_CURRENT_TIME when we claim the
@@ -556,7 +556,7 @@ weston_wm_handle_xfixes_selection_notify(struct weston_wm *wm,
 	 * answer TIMESTAMP conversion requests correctly. */
 	if (xfixes_selection_notify->owner == wm->selection_window) {
 		wm->selection_timestamp = xfixes_selection_notify->timestamp;
-		fprintf(stderr, "our window, skipping\n");
+		weston_log("our window, skipping\n");
 		return;
 	}
 
@@ -607,13 +607,13 @@ weston_wm_set_selection(struct wl_listener *listener, void *data)
 	if (source->offer_interface == &data_offer_interface)
 		return;
 
-	fprintf(stderr, "set selection\n");
+	weston_log("set selection\n");
 
 	p = source->mime_types.data;
 	end = (const char **)
 		((char *) source->mime_types.data + source->mime_types.size);
 	while (p < end) {
-		fprintf(stderr, "  %s\n", *p);
+		weston_log("  %s\n", *p);
 		if (strcmp(*p, "text/plain") == 0 ||
 		    strcmp(*p, "text/plain;charset=utf-8") == 0)
 			has_text_plain = 1;
diff --git a/src/xwayland/window-manager.c b/src/xwayland/window-manager.c
index b8be54c..827dccb 100644
--- a/src/xwayland/window-manager.c
+++ b/src/xwayland/window-manager.c
@@ -36,6 +36,7 @@
 
 #include "../../shared/cairo-util.h"
 #include "../compositor.h"
+#include "../log.h"
 #include "xserver-server-protocol.h"
 #include "hash.h"
 
@@ -148,13 +149,13 @@ dump_property(struct weston_wm *wm,
 	int width, len;
 	uint32_t i;
 
-	width = fprintf(stderr, "%s: ", get_atom_name(wm->conn, property));
+	width = weston_log_continue("%s: ", get_atom_name(wm->conn, property));
 	if (reply == NULL) {
-		fprintf(stderr, "(no reply)\n");
+		weston_log_continue("(no reply)\n");
 		return;
 	}
 
-	width += fprintf(stderr,
+	width += weston_log_continue(
 			 "%s/%d, length %d (value_len %d): ",
 			 get_atom_name(wm->conn, reply->type),
 			 reply->format,
@@ -163,7 +164,7 @@ dump_property(struct weston_wm *wm,
 
 	if (reply->type == wm->atom.incr) {
 		incr_value = xcb_get_property_value(reply);
-		fprintf(stderr, "%d\n", *incr_value);
+		weston_log_continue("%d\n", *incr_value);
 	} else if (reply->type == wm->atom.utf8_string ||
 	      reply->type == wm->atom.string) {
 		text_value = xcb_get_property_value(reply);
@@ -171,23 +172,23 @@ dump_property(struct weston_wm *wm,
 			len = 40;
 		else
 			len = reply->value_len;
-		fprintf(stderr, "\"%.*s\"\n", len, text_value);
+		weston_log_continue("\"%.*s\"\n", len, text_value);
 	} else if (reply->type == XCB_ATOM_ATOM) {
 		atom_value = xcb_get_property_value(reply);
 		for (i = 0; i < reply->value_len; i++) {
 			name = get_atom_name(wm->conn, atom_value[i]);
 			if (width + strlen(name) + 2 > 78) {
-				fprintf(stderr, "\n    ");
+				weston_log_continue("\n    ");
 				width = 4;
 			} else if (i > 0) {
-				width += fprintf(stderr, ", ");
+				width +=  weston_log_continue(", ");
 			}
 
-			width += fprintf(stderr, "%s", name);
+			width +=  weston_log_continue("%s", name);
 		}
-		fprintf(stderr, "\n");
+		weston_log_continue("\n");
 	} else {
-		fprintf(stderr, "huh?\n");
+		weston_log_continue("huh?\n");
 	}
 }
 
@@ -339,7 +340,7 @@ weston_wm_handle_configure_request(struct weston_wm *wm, xcb_generic_event_t *ev
 	uint32_t mask, values[16];
 	int x, y, width, height, i = 0;
 
-	fprintf(stderr, "XCB_CONFIGURE_REQUEST (window %d) %d,%d @ %dx%d\n",
+	weston_log("XCB_CONFIGURE_REQUEST (window %d) %d,%d @ %dx%d\n",
 		configure_request->window,
 		configure_request->x, configure_request->y,
 		configure_request->width, configure_request->height);
@@ -389,7 +390,7 @@ weston_wm_handle_configure_notify(struct weston_wm *wm, xcb_generic_event_t *eve
 
 	window = hash_table_lookup(wm->window_hash, configure_notify->window);
 
-	fprintf(stderr, "XCB_CONFIGURE_NOTIFY (%s window %d) %d,%d @ %dx%d\n",
+	weston_log("XCB_CONFIGURE_NOTIFY (%s window %d) %d,%d @ %dx%d\n",
 		configure_notify->window == window->id ? "client" : "frame",
 		configure_notify->window,
 		configure_notify->x, configure_notify->y,
@@ -475,7 +476,7 @@ weston_wm_handle_map_request(struct weston_wm *wm, xcb_generic_event_t *event)
 	int x, y, width, height;
 
 	if (our_resource(wm, map_request->window)) {
-		fprintf(stderr, "XCB_MAP_REQUEST (window %d, ours)\n",
+		weston_log("XCB_MAP_REQUEST (window %d, ours)\n",
 			map_request->window);
 		return;
 	}
@@ -515,7 +516,7 @@ weston_wm_handle_map_request(struct weston_wm *wm, xcb_generic_event_t *event)
 	xcb_configure_window(wm->conn, window->id,
 			     XCB_CONFIG_WINDOW_BORDER_WIDTH, values);
 
-	fprintf(stderr, "XCB_MAP_REQUEST (window %d, %p, frame %d)\n",
+	weston_log("XCB_MAP_REQUEST (window %d, %p, frame %d)\n",
 		window->id, window, window->frame_id);
 
 	xcb_map_window(wm->conn, map_request->window);
@@ -538,12 +539,12 @@ weston_wm_handle_map_notify(struct weston_wm *wm, xcb_generic_event_t *event)
 	xcb_map_notify_event_t *map_notify = (xcb_map_notify_event_t *) event;
 
 	if (our_resource(wm, map_notify->window)) {
-			fprintf(stderr, "XCB_MAP_NOTIFY (window %d, ours)\n",
+			weston_log("XCB_MAP_NOTIFY (window %d, ours)\n",
 				map_notify->window);
 			return;
 	}
 
-	fprintf(stderr, "XCB_MAP_NOTIFY (window %d)\n", map_notify->window);
+	weston_log("XCB_MAP_NOTIFY (window %d)\n", map_notify->window);
 }
 
 static void
@@ -553,8 +554,7 @@ weston_wm_handle_unmap_notify(struct weston_wm *wm, xcb_generic_event_t *event)
 		(xcb_unmap_notify_event_t *) event;
 	struct weston_wm_window *window;
 
-	fprintf(stderr,
-		"XCB_UNMAP_NOTIFY (window %d, event %d%s)\n",
+	weston_log("XCB_UNMAP_NOTIFY (window %d, event %d%s)\n",
 		unmap_notify->window,
 		unmap_notify->event,
 		our_resource(wm, unmap_notify->window) ? ", ours" : "");
@@ -674,10 +674,10 @@ weston_wm_handle_property_notify(struct weston_wm *wm, xcb_generic_event_t *even
 	if (window)
 		window->properties_dirty = 1;
 
-	fprintf(stderr, "XCB_PROPERTY_NOTIFY: window %d, ",
+	weston_log("XCB_PROPERTY_NOTIFY: window %d, ",
 		property_notify->window);
 	if (property_notify->state == XCB_PROPERTY_DELETE)
-		fprintf(stderr, "deleted\n");
+		weston_log("deleted\n");
 	else
 		read_and_dump_property(wm, property_notify->window,
 				       property_notify->atom);
@@ -696,7 +696,7 @@ weston_wm_window_create(struct weston_wm *wm,
 
 	window = malloc(sizeof *window);
 	if (window == NULL) {
-		fprintf(stderr, "failed to allocate window\n");
+		weston_log("failed to allocate window\n");
 		return;
 	}
 
@@ -727,8 +727,7 @@ weston_wm_handle_create_notify(struct weston_wm *wm, xcb_generic_event_t *event)
 	xcb_create_notify_event_t *create_notify =
 		(xcb_create_notify_event_t *) event;
 
-	fprintf(stderr,
-		"XCB_CREATE_NOTIFY (window %d, width %d, height %d%s%s)\n",
+	weston_log("XCB_CREATE_NOTIFY (window %d, width %d, height %d%s%s)\n",
 		create_notify->window,
 		create_notify->width, create_notify->height,
 		create_notify->override_redirect ? ", override" : "",
@@ -748,7 +747,7 @@ weston_wm_handle_destroy_notify(struct weston_wm *wm, xcb_generic_event_t *event
 		(xcb_destroy_notify_event_t *) event;
 	struct weston_wm_window *window;
 
-	fprintf(stderr, "XCB_DESTROY_NOTIFY, win %d, event %d%s\n",
+	weston_log("XCB_DESTROY_NOTIFY, win %d, event %d%s\n",
 		destroy_notify->window,
 		destroy_notify->event,
 		our_resource(wm, destroy_notify->window) ? ", ours" : "");
@@ -767,8 +766,7 @@ weston_wm_handle_reparent_notify(struct weston_wm *wm, xcb_generic_event_t *even
 		(xcb_reparent_notify_event_t *) event;
 	struct weston_wm_window *window;
 
-	fprintf(stderr,
-		"XCB_REPARENT_NOTIFY (window %d, parent %d, event %d)\n",
+	weston_log("XCB_REPARENT_NOTIFY (window %d, parent %d, event %d)\n",
 		reparent_notify->window,
 		reparent_notify->parent,
 		reparent_notify->event);
@@ -837,7 +835,7 @@ weston_wm_handle_client_message(struct weston_wm *wm,
 
 	window = hash_table_lookup(wm->window_hash, client_message->window);
 
-	fprintf(stderr, "XCB_CLIENT_MESSAGE (%s %d %d %d %d %d)\n",
+	weston_log("XCB_CLIENT_MESSAGE (%s %d %d %d %d %d)\n",
 		get_atom_name(wm->conn, client_message->type),
 		client_message->data.data32[0],
 		client_message->data.data32[1],
@@ -860,7 +858,7 @@ weston_wm_handle_button(struct weston_wm *wm, xcb_generic_event_t *event)
 	struct theme *t = wm->theme;
 	int width, height;
 
-	fprintf(stderr, "XCB_BUTTON_%s (detail %d)\n",
+	weston_log("XCB_BUTTON_%s (detail %d)\n",
 		button->response_type == XCB_BUTTON_PRESS ?
 		"PRESS" : "RELEASE", button->detail);
 
@@ -906,7 +904,7 @@ weston_wm_handle_event(int fd, uint32_t mask, void *data)
 
 	while (event = xcb_poll_for_event(wm->conn), event != NULL) {
 		if (weston_wm_handle_selection_event(wm, event)) {
-			fprintf(stderr, "handled by selection code\n");
+			weston_log("handled by selection code\n");
 			free(event);
 			count++;
 			continue;
@@ -942,7 +940,7 @@ weston_wm_handle_event(int fd, uint32_t mask, void *data)
 			weston_wm_handle_destroy_notify(wm, event);
 			break;
 		case XCB_MAPPING_NOTIFY:
-			fprintf(stderr, "XCB_MAPPING_NOTIFY\n");
+			weston_log("XCB_MAPPING_NOTIFY\n");
 			break;
 		case XCB_PROPERTY_NOTIFY:
 			weston_wm_handle_property_notify(wm, event);
@@ -1042,7 +1040,7 @@ wxs_wm_get_resources(struct weston_wm *wm)
 
 	wm->xfixes = xcb_get_extension_data(wm->conn, &xcb_xfixes_id);
 	if (!wm->xfixes || !wm->xfixes->present)
-		fprintf(stderr, "xfixes not available\n");
+		weston_log("xfixes not available\n");
 
 	xfixes_cookie = xcb_xfixes_query_version(wm->conn,
 						 XCB_XFIXES_MAJOR_VERSION,
@@ -1050,7 +1048,7 @@ wxs_wm_get_resources(struct weston_wm *wm)
 	xfixes_reply = xcb_xfixes_query_version_reply(wm->conn,
 						      xfixes_cookie, NULL);
 
-	printf("xfixes version: %d.%d\n",
+	weston_log("xfixes version: %d.%d\n",
 	       xfixes_reply->major_version, xfixes_reply->minor_version);
 
 	free(xfixes_reply);
@@ -1136,7 +1134,7 @@ weston_wm_create(struct weston_xserver *wxs)
 	}
 
 	if (socketpair(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0, sv) < 0) {
-		fprintf(stderr, "socketpair failed\n");
+		weston_log("socketpair failed\n");
 		hash_table_destroy(wm->window_hash);
 		free(wm);
 		return NULL;
@@ -1149,7 +1147,7 @@ weston_wm_create(struct weston_xserver *wxs)
 	/* xcb_connect_to_fd takes ownership of the fd. */
 	wm->conn = xcb_connect_to_fd(sv[0], NULL);
 	if (xcb_connection_has_error(wm->conn)) {
-		fprintf(stderr, "xcb_connect_to_fd failed\n");
+		weston_log("xcb_connect_to_fd failed\n");
 		close(sv[0]);
 		hash_table_destroy(wm->window_hash);
 		free(wm);
@@ -1219,7 +1217,7 @@ weston_wm_create(struct weston_xserver *wxs)
 	wl_signal_add(&wxs->compositor->activate_signal,
 		      &wm->activate_listener);
 
-	fprintf(stderr, "created wm\n");
+	weston_log("created wm\n");
 
 	return wm;
 }
@@ -1244,7 +1242,7 @@ surface_destroy(struct wl_listener *listener, void *data)
 		container_of(listener,
 			     struct weston_wm_window, surface_destroy_listener);
 
-	fprintf(stderr, "surface for xid %d destroyed\n", window->id);
+	weston_log("surface for xid %d destroyed\n", window->id);
 }
 
 static struct weston_wm_window *
@@ -1363,11 +1361,11 @@ xserver_set_window_id(struct wl_client *client, struct wl_resource *resource,
 
 	window = hash_table_lookup(wm->window_hash, id);
 	if (window == NULL) {
-		fprintf(stderr, "set_window_id for unknown window %d\n", id);
+		weston_log("set_window_id for unknown window %d\n", id);
 		return;
 	}
 
-	fprintf(stderr, "set_window_id %d for surface %p\n", id, surface);
+	weston_log("set_window_id %d for surface %p\n", id, surface);
 
 	weston_wm_window_read_properties(window);
 
-- 
1.7.5.4



More information about the wayland-devel mailing list