Discussion:
[RFC] implement log facility using syslog
(too old to reply)
Tiago Vignatti
2011-07-22 20:01:50 UTC
Permalink
Hi all,

I wanted to use an already existent library for logging; the first that came
to my mind was one with syslog interface. I like because there is a lot of
implementations around, it's simple and kinda flexible. For instance, I can get
the whole system log together with the Wayland one if I want, or just the
latter separately. One even could send the logs over through the network to a
remote server or output it to a named fifo.

However, it seems people are not that excited anymore with syslog
implementations for some reason and implementing their own mechanism for each
software [0]. I tend to see also a bunch of Meego applications dumping log on
.xsession-errors. I don't get it, really!

A drawback I see, is that it requires a small intervention on the system
configuration, having to edit a shared file (/etc/syslog.conf) in a way to
route the messages for a particular location, say /var/log/wayland.log. So I'm
assuming and hardcoding LOG_LOCAL0 for wayland now. Ugly.

I'd like to hear your first feedback regarding the usage of syslog and also
regarding the API for logging. If the discussions will be too tense on the
syslog stuff then I think we just go for own compositor's logging
implementation.

Thanks!

[0] http://lists.freedesktop.org/archives/systemd-devel/2011-June/002682.html
Tiago Vignatti
2011-07-22 20:01:51 UTC
Permalink
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, ...);

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
Kristian Høgsberg
2011-07-25 15:18:53 UTC
Permalink
On Fri, Jul 22, 2011 at 1:01 PM, Tiago Vignatti
Post by Tiago Vignatti
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
Post by Tiago Vignatti
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
? ?local0.* ? ?/var/log/wayland.log
? ?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) {
+ ? ? ? ? ? ? ? vsyslog(LOG_INFO, f, args);
+ ? ? ? ? ? ? ? break;
+ ? ? ? ? ? ? ? vsyslog(LOG_WARNING, f, args);
+ ? ? ? ? ? ? ? vfprintf(stderr, f, args);
+ ? ? ? ? ? ? ? break;
+ ? ? ? ? ? ? ? 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
Tiago Vignatti
2011-07-25 16:03:51 UTC
Permalink
Post by Kristian Høgsberg
On Fri, Jul 22, 2011 at 1:01 PM, Tiago Vignatti
Post by Tiago Vignatti
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.
right, but then we miss the logging on client side. And I guess it's
okay, but if we want to extend for a debugging functionality then we
have to re-think and squash it anyway in the protocol implementation.
I'll come back with this idea later.

About handling errors in the protocol, I think we are not doing bad
cause most of the output generated is due sanity check from system calls
(apart from the debug's wl_closure_print).

Tiago

Tiago Vignatti
2011-07-22 20:01:52 UTC
Permalink
Signed-off-by: Tiago Vignatti <tiago.vignatti at intel.com>
---
clients/simple-egl.c | 4 ++++
compositor/compositor.c | 4 ++++
2 files changed, 8 insertions(+), 0 deletions(-)

diff --git a/clients/simple-egl.c b/clients/simple-egl.c
index f2a1f77..9941164 100644
--- a/clients/simple-egl.c
+++ b/clients/simple-egl.c
@@ -352,6 +352,10 @@ main(int argc, char **argv)
display.display = wl_display_connect(NULL);
assert(display.display);

+ wl_log(WL_INFO, "INFO\n");
+ wl_log(WL_WARNING, "WARNING\n");
+ wl_log(WL_ERROR, "ERROR\n");
+
wl_display_add_global_listener(display.display,
display_handle_global, &display);

diff --git a/compositor/compositor.c b/compositor/compositor.c
index 177de54..96aba8e 100644
--- a/compositor/compositor.c
+++ b/compositor/compositor.c
@@ -2054,6 +2054,10 @@ int main(int argc, char *argv[])

display = wl_display_create();

+ wl_log(WL_INFO, "INFO\n");
+ wl_log(WL_WARNING, "WARNING\n");
+ wl_log(WL_ERROR, "ERROR\n");
+
ec = NULL;

if (!backend) {
--
1.7.2.2
Marty Jack
2011-07-22 21:34:25 UTC
Permalink
Post by Tiago Vignatti
Hi all,
I wanted to use an already existent library for logging; the first that came
to my mind was one with syslog interface. I like because there is a lot of
implementations around, it's simple and kinda flexible. For instance, I can get
the whole system log together with the Wayland one if I want, or just the
latter separately. One even could send the logs over through the network to a
remote server or output it to a named fifo.
However, it seems people are not that excited anymore with syslog
implementations for some reason and implementing their own mechanism for each
software [0]. I tend to see also a bunch of Meego applications dumping log on
.xsession-errors. I don't get it, really!
A drawback I see, is that it requires a small intervention on the system
configuration, having to edit a shared file (/etc/syslog.conf) in a way to
route the messages for a particular location, say /var/log/wayland.log. So I'm
assuming and hardcoding LOG_LOCAL0 for wayland now. Ugly.
I'd like to hear your first feedback regarding the usage of syslog and also
regarding the API for logging. If the discussions will be too tense on the
syslog stuff then I think we just go for own compositor's logging
implementation.
Thanks!
[0] http://lists.freedesktop.org/archives/systemd-devel/2011-June/002682.html
_______________________________________________
wayland-devel mailing list
wayland-devel at lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/wayland-devel
The primary reason you wouldn't use syslog to log user messages is that it opens the possibility for an unprivileged user process to maliciously consume the root partition. Logging to the equivalent of ~/.Xsession-errors is the right way to go because it puts the log traffic into the user's home directory. It would be okay to use syslog or a log file in /var/log or such to log messages from the system compositor that pertain to things that happen outside of when a user is logged in.
Christian Hergert
2011-07-22 22:32:49 UTC
Permalink
Post by Tiago Vignatti
Hi all,
I wanted to use an already existent library for logging; the first that came
to my mind was one with syslog interface. I like because there is a lot of
implementations around, it's simple and kinda flexible. For instance, I can get
the whole system log together with the Wayland one if I want, or just the
latter separately. One even could send the logs over through the network to a
remote server or output it to a named fifo.
However, it seems people are not that excited anymore with syslog
implementations for some reason and implementing their own mechanism for each
software [0]. I tend to see also a bunch of Meego applications dumping log on
.xsession-errors. I don't get it, really!
A drawback I see, is that it requires a small intervention on the system
configuration, having to edit a shared file (/etc/syslog.conf) in a way to
route the messages for a particular location, say /var/log/wayland.log. So I'm
assuming and hardcoding LOG_LOCAL0 for wayland now. Ugly.
I'd like to hear your first feedback regarding the usage of syslog and also
regarding the API for logging. If the discussions will be too tense on the
syslog stuff then I think we just go for own compositor's logging
implementation.
Thanks!
[0] http://lists.freedesktop.org/archives/systemd-devel/2011-June/002682.html
_______________________________________________
wayland-devel mailing list
wayland-devel at lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/wayland-devel
The primary reason you wouldn't use syslog to log user messages is that it opens the possibility for an unprivileged user process to maliciously consume the root partition. ?Logging to the equivalent of ~/.Xsession-errors is the right way to go because it puts the log traffic into the user's home directory. ?It would be okay to use syslog or a log file in /var/log or such to log messages from the system compositor that pertain to things that happen outside of when a user is logged in.
Can syslog() potentially block? If so, that might be an issue of
concern. I don't think it is, at least officially stated, that
syslog() is re-entrant safe (which may be of concern with regard to
how signals are handled).

Anyway, I don't really have the answers to those, just thought I'd mention it.

-- Christian
Tiago Vignatti
2011-07-25 09:38:19 UTC
Permalink
Post by Christian Hergert
Can syslog() potentially block? If so, that might be an issue of
concern. I don't think it is, at least officially stated, that
syslog() is re-entrant safe (which may be of concern with regard to
how signals are handled).
well, this depends the way syslog is implemented. And actually that's my
main selling point for using syslog instead our own logging
implementation: to push the efforts for someone that *knows* how to log.

For instance, rsyslog seem pretty up to date and being developed often.
I bet it deals nicely with a bunch of app consumers, not blocking them.


Thanks!
Tiago
Tiago Vignatti
2011-07-25 09:24:38 UTC
Permalink
Post by Marty Jack
The primary reason you wouldn't use syslog to log user messages is that it opens the possibility for an unprivileged user process to maliciously consume the root partition. Logging to the equivalent of ~/.Xsession-errors is the right way to go because it puts the log traffic into the user's home directory. It would be okay to use syslog or a log file in /var/log or such to log messages from the system compositor that pertain to things that happen outside of when a user is logged in.
syslog implementations let you redirect however you want the logs, for
instance in a home directory or even .xsessions-errors :)

Tiago
Continue reading on narkive:
Loading...