Bug 73339 - libwayland: the library should not print anything to stderr
Summary: libwayland: the library should not print anything to stderr
Alias: None
Product: Wayland
Classification: Unclassified
Component: wayland (show other bugs)
Version: unspecified
Hardware: Other All
: medium normal
Assignee: Wayland bug list
QA Contact:
Depends on:
Reported: 2014-01-07 00:14 UTC by nfxjfg
Modified: 2014-04-30 19:20 UTC (History)
0 users

See Also:
i915 platform:
i915 features:


Description nfxjfg 2014-01-07 00:14:18 UTC
For example, the library prints a message to stderr if the XDG_RUNTIME_DIR envrionment variable is not set:


There are other cases.

A library should normally never print anything, unless it can be overridden by setting a message callback. Outputting something, even to stderr, can cause for terminal programs which want to keep their output clean, especially in case of non-fatal errors, or for example catch the error message and send it somewhere else.
Comment 1 Pekka Paalanen 2014-02-21 06:44:17 UTC
should fix part of the prints, but I guess the message you referred to is still there?

OTOH, see
which is going the opposite way. Is that ok?

libwayland has at least 3 different libraries.
Comment 2 nfxjfg 2014-02-21 07:53:53 UTC
Well, you're almost there.

Remember how xlib had only a process wide error handler, and everyone hated it? You're making the same mistake.

This is a very common mistake library designers do, and many libraries suffer from this mistake - or rather, libraries using other libraries suffer from it, because now they have to fight with other libraries for the log callback. That everyone makes this error doesn't make it any less wrong.

I suggest that wl_log gets a context argument, and that the wl_log_handler can be set per-context by the library user.

(Maybe this is less severe than the xlib issue, because wl_log_handler really is only a log function and not more, but still.)
Comment 3 Kristian Høgsberg 2014-04-30 19:20:46 UTC
wl_log is only for logging not for handling protocol errors.  If we add
a mechanism for handling protocol errors, it will be a per-object handler.

With that, this handles the remaining stderr printing:

commit 88f3bd84c8ea8f0b3526f970388ef76baa231fe2
Author: Kristian Høgsberg <krh@bitplanet.net>
Date:   Wed Apr 30 12:18:52 2014 -0700

    Avoid printing to stderr
    Use wl_log in the last few places where we print to stderr.  Remove
    logging in a couple of places where we properly return an error code.

Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.