[PATCH] wayland: introduce logging with syslog

Kristian Høgsberg krh at bitplanet.net
Mon Jul 25 08:18:53 PDT 2011


On Fri, Jul 22, 2011 at 1:01 PM, Tiago Vignatti
<tiago.vignatti at intel.com> wrote:
> Three level of messages are possible, which are sent to syslog: WL_INFO,
> WL_WARNING and WL_ERROR; the last two are printed also to stderr due
> sanity. The only interface for the compositor and clients is
>
>    void wl_log(int level, const char *f, ...);

syslog or not, we don't wan't logging in the core libraries.  For the
stray fprintf error cases in the libraries, we should clean that up by
handling the error better or return the error in the API.  The logging
should be only in wayland-compositor in the wayland-demos repo.

Kristian

> It requires a small intervention on the system configuration and
> assumption that LOG_LOCAL0 routes for wayland logging. So in MeeGo for
> instance, there is sysklogd package which provides syslogd and I had to
> edit /etc/syslog.conf, adding a line like this:
>
>    local0.*    /var/log/wayland.log
>
> then I (re-)started the daemon:
>
>    systemd
>
> Signed-off-by: Tiago Vignatti <tiago.vignatti at intel.com>
> ---
>  wayland/wayland-client.c |    3 +++
>  wayland/wayland-server.c |    3 +++
>  wayland/wayland-util.c   |   36 ++++++++++++++++++++++++++++++++++++
>  wayland/wayland-util.h   |   14 ++++++++++++++
>  4 files changed, 56 insertions(+), 0 deletions(-)
>
> diff --git a/wayland/wayland-client.c b/wayland/wayland-client.c
> index 9d1f66b..728fa22 100644
> --- a/wayland/wayland-client.c
> +++ b/wayland/wayland-client.c
> @@ -369,6 +369,8 @@ wl_display_connect(const char *name)
>        if (debug)
>                wl_debug = 1;
>
> +       wl_log_open("client");
> +
>        display = malloc(sizeof *display);
>        if (display == NULL)
>                return NULL;
> @@ -441,6 +443,7 @@ wl_display_destroy(struct wl_display *display)
>
>        close(display->fd);
>        free(display);
> +       wl_log_close();
>  }
>
>  WL_EXPORT int
> diff --git a/wayland/wayland-server.c b/wayland/wayland-server.c
> index 2019cb4..6285708 100644
> --- a/wayland/wayland-server.c
> +++ b/wayland/wayland-server.c
> @@ -589,6 +589,8 @@ wl_display_create(void)
>        if (debug)
>                wl_debug = 1;
>
> +       wl_log_open("compositor");
> +
>        display = malloc(sizeof *display);
>        if (display == NULL)
>                return NULL;
> @@ -647,6 +649,7 @@ wl_display_destroy(struct wl_display *display)
>                free(global);
>
>        free(display);
> +       wl_log_close();
>  }
>
>  WL_EXPORT void
> diff --git a/wayland/wayland-util.c b/wayland/wayland-util.c
> index 3643274..a28530c 100644
> --- a/wayland/wayland-util.c
> +++ b/wayland/wayland-util.c
> @@ -121,3 +121,39 @@ wl_array_copy(struct wl_array *array, struct wl_array *source)
>        wl_array_add(array, source->size);
>        memcpy(array->data, source->data, source->size);
>  }
> +
> +void
> +wl_log_open(const char *ident)
> +{
> +       setlogmask (LOG_UPTO (LOG_INFO));
> +       openlog (ident, LOG_CONS | LOG_NDELAY | LOG_PID, LOG_LOCAL0);
> +}
> +
> +void
> +wl_log_close(void)
> +{
> +       closelog();
> +}
> +
> +WL_EXPORT void
> +wl_log(int level, const char *f, ...)
> +{
> +       va_list args;
> +       va_start(args, f);
> +
> +       /* WL_WARNING and WL_ERROR go to stderr output as well */
> +       switch(level) {
> +       case WL_INFO:
> +               vsyslog(LOG_INFO, f, args);
> +               break;
> +       case WL_WARNING:
> +               vsyslog(LOG_WARNING, f, args);
> +               vfprintf(stderr, f, args);
> +               break;
> +       case WL_ERROR:
> +               vsyslog(LOG_ERR, f, args);
> +               vfprintf(stderr, f, args);
> +               break;
> +       }
> +       va_end(args);
> +}
> diff --git a/wayland/wayland-util.h b/wayland/wayland-util.h
> index a9f869a..63a32f0 100644
> --- a/wayland/wayland-util.h
> +++ b/wayland/wayland-util.h
> @@ -28,6 +28,9 @@ extern "C" {
>  #endif
>
>  #include <inttypes.h>
> +#include <syslog.h>
> +#include <stdio.h>
> +#include <stdarg.h>
>
>  /* GCC visibility */
>  #if defined(__GNUC__) && __GNUC__ >= 4
> @@ -145,6 +148,17 @@ void wl_array_release(struct wl_array *array);
>  void *wl_array_add(struct wl_array *array, int size);
>  void wl_array_copy(struct wl_array *array, struct wl_array *source);
>
> +/**
> + * logging mechanism
> + */
> +#define WL_INFO 0
> +#define WL_WARNING 1
> +#define WL_ERROR 2
> +
> +void wl_log_open(const char *ident);
> +void wl_log_close(void);
> +void wl_log(int level, const char *f, ...);
> +
>  #ifdef  __cplusplus
>  }
>  #endif
> --
> 1.7.2.2
>
> _______________________________________________
> wayland-devel mailing list
> wayland-devel at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/wayland-devel
>


More information about the wayland-devel mailing list