Cannot get nautilus debug log without debug messages from dependencies
Steps to reproduce
- Force quit nautilus (if running)
- Launch nautilus with debug messages enabled, by running the following command in a Terminal window:
G_MESSAGES_DEBUG="all" NAUTILUS_DEBUG="Window" nautilus
Current behavior
The terminal output is flooded with debug messages from dependency libraries (GIO, Tracker, dconf, etc.).
Expected behavior
We should be able to get debug log with only those messages that originate from nautilus own source code.
Problem investigation
This happens because we are not defining G_LOG_DOMAIN
, so the only way to get nautilus debug messages is to get "all" messages regardless of domain. That's why G_MESSAGES_DEBUG="all"
is required.
This is adviced against by the GLib documentation:
If undefined, it defaults to the default NULL (or "") log domain; this is not advisable, as it cannot be filtered against using the G_MESSAGES_DEBUG environment variable.
Indeed, we can't make use of G_MESSAGES_DEBUG
because we are defining our own domains because we invent our own NAUTILUS_DEBUG=
environment variable. This, too, is advised against by the GLib documentation:
It is recommended that custom log writer functions re-use the G_MESSAGES_DEBUG environment variable, rather than inventing a custom one, so that developers can re-use the same debugging techniques and tools across projects.
Proposed solution
Following the advice of the documentation:
- Drop the
NAUTILUS_DEBUG
environment variable. - Drop our custom
DEBUG
and defineG_LOG_DOMAIN
at the top of source files instead. - When defining
G_LOG_DOMAIN
, follow the recommendeddomain-subdomain
format. E.g.nautilus-window
.
A positive side effect of this solution is that it should remove many lines of code from src/nautilus-debug.c and src/nautilus-debug.h.
An optional follow-up to this work would be replacing our custom DEBUG()
macro with the upstream g_debug()
macro.
(As a whole, this is one of this leftover tasks from the #224 epic. But it's completely isolated from the rest, so it can be solved independently.)