Skip to content

Add Debug preferences for writing to the system log - #1907

Open
djp3 wants to merge 13 commits into
ianyh:developmentfrom
djp3:debug-logging-preferences
Open

djp3 wants to merge 13 commits into
ianyh:developmentfrom
djp3:debug-logging-preferences

Conversation

@djp3

@djp3 djp3 commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Amethyst writes a steady commentary about what it does: windows being added and removed, screens being asked to rearrange, and why a rearrangement was skipped. In a release build none of it goes anywhere. The logging library has no output connected, so when a user reports that a window was left untiled or a screen stopped rearranging, there is nothing to read after the fact.

There is one hidden exception. Started from the Terminal with the argument --log, the app hands every line to the plain system logging call, which files them under the process name among the many lines macOS itself writes about the app. Few people know the switch exists, it does not survive a relaunch, and the lines are awkward to pick out.

Change

Two commits.

  1. Write the --log output to the system log under the app's subsystem. A destination of its own writes the lines to the unified log under the app's bundle identifier, in the category diagnostics, so one predicate finds them all:

    log show --last 15m --predicate 'subsystem == "com.amethyst.Amethyst"'
    

    The system stamps each line with the time, so a line carries the level, the source file, the function, the line number and the message. Errors go in at the system's error level and everything else at the default level, which the system keeps on disk.

  2. Add Debug preferences for writing to the system log. Two checkboxes on the Debug tab under a "Write to system log:" label, remembered across launches: "All diagnostic details", off by default, which writes every line exactly as --log does, and "Warnings and errors", on by default, which writes only those. Turning on every detail also turns warnings and errors on and greys that box out, since everything includes them. A small note under the pair says that window titles will be logged in local log files, because that is how Amethyst describes a window. The boxes take effect at once, in either direction, and --log still works. The keys debug-log-details and debug-log-warnings can be set from a configuration file like any other setting and are documented.

Notes for review

  • Nothing new is logged. The change only decides where the existing lines go. At the defaults a release build writes its warnings and errors, which are rare, and nothing else. With both boxes off it is exactly as quiet as today: the logging library builds a message only when some output will accept it, so the text is never assembled.
  • A single destination is connected at most once, with its threshold adjusted when the boxes change, so no line is written twice.
  • "About layouts" is left alone. It toggles the description line in the on-screen layout notice and has nothing to do with the log.

Tests

SystemLogDestinationTests (2) check the line format and the subsystem. DiagnosticLoggingTests (5) check the threshold rule, the two preferences, and the Debug pane loaded from its layout file: the checkboxes are present, bound to the right keys, and the layout is unambiguous. The full suite passes.

djp3 added 3 commits October 30, 2026 18:42
Started with --log, the app handed every log line to NSLog, which files
them under the process name among the many lines macOS itself writes
about the app. A destination of its own now writes them to the unified
log under the app's bundle identifier, in the category "diagnostics", so
one predicate finds them all:

    log show --predicate 'subsystem == "com.amethyst.Amethyst"'

The system stamps every line with the time, so a line carries the level,
the source file, the function, the line number and the message. Errors
are written at the system's error level, everything else at the default
level, which the system keeps on disk.
Two checkboxes on the Debug tab, under a "Write to system log:" label and
off by default: "All diagnostic details", which writes every log line the
way starting the app with --log does, and "Warnings and errors", which
writes only those. Turning on every detail also turns warnings and errors
on and greys that box out, since everything includes them. A note under
the pair says that window titles will be logged in local log files.

DiagnosticLogging connects the system log destination according to the
two preferences and the --log argument, and follows the preferences as
they change, so the boxes take effect at once and no line is written
twice. The keys debug-log-details and debug-log-warnings persist like
every other setting, can be set from a configuration file, and are
documented.
A release build now writes its warnings and errors to the system log
unless the Debug tab's "Warnings and errors" box is turned off. Every
detail stays off by default.
djp3 added a commit to djp3/Amethyst that referenced this pull request Oct 31, 2026
The skip lines go through the logger the rest of the app uses: as
warnings, or as information for the expected case of a non-user Space
being frontmost. A release build writes them to the system log according
to the Debug tab's logging preferences (ianyh#1907), or when started with
--log, and nowhere otherwise.
djp3 added a commit to djp3/Amethyst that referenced this pull request Oct 31, 2026
The lines about adopting applications and their windows go through the
logger the rest of the app uses instead of a log category of their own:
a give-up, a window with no adopted application and a window that could
not be tracked as warnings or errors, and a late success, an adoption on
activation, a retry and a window floated for its size as information. A
failed observer registration is logged once rather than on two channels.
A release build writes these lines to the system log according to the
Debug tab's logging preferences (ianyh#1907), or when started with --log, and
nowhere otherwise.
djp3 added a commit to djp3/Amethyst that referenced this pull request Oct 31, 2026
The animation and capture lines go through the logger the rest of the
app uses instead of a log category of their own: the timing summaries,
the size diagnostic and an unavailable snapshot as debugging detail, and
a glide that never reported completion, a failed recapture, a window not
redrawn at hand-off, and a paused or resumed window capture as warnings.
A release build writes these lines to the system log according to the
Debug tab's logging preferences (ianyh#1907), or when started with --log, and
nowhere otherwise.
djp3 added a commit to djp3/Amethyst that referenced this pull request Oct 31, 2026
Each step a drag goes through is logged as debugging detail: a reflow
held because the mouse button is down and the moment the button comes
up, each quarter-second wait of the hand-over with its reason, a window
left alone because it lies on no screen or no layout has placed it, the
hand-over itself with both screens, the drop with the window it swaps
with or the absence of one, and the start of every reflow with the
screen and the windows it holds. A release build writes these lines
nowhere unless it is started with --log or the Debug tab's logging
preferences (ianyh#1907) ask for every detail.
@djp3
djp3 marked this pull request as ready for review October 31, 2026 03:11
djp3 added 4 commits November 6, 2026 11:21
A window prints as its process, number and frame in a log line. A line
that names a window hands the title over separately, and the system log
destination writes it as a private field beside the public text, so the
unified log hides it unless private data is revealed on that Mac. The
title is read only when a destination actually writes the line.
… tab

The app carries a configuration profile that turns on private data in the
system log for Amethyst's subsystem only. A button on the Debug tab hands
it to macOS, which installs it through System Settings with an
administrator's approval; once installed, log lines show their window
titles on that Mac. A test checks the profile is bundled and scoped to the
app's subsystem.
A build phase puts the profile into the app's resources. When the app is
being signed with a Developer ID certificate, the phase signs the profile
with that same certificate, found by its subject key ID from the
fingerprint Xcode chose, so System Settings shows it as verified. Any
other build copies the profile unsigned. The script explains how to make
an archive sign with the Developer ID from the start, and the profile
test unwraps a signed copy before reading it.
The button reads "Reveal Window Titles in System Logs" and is enabled
only while something is written to the system log. Clicking it hands the
profile to macOS and then opens System Settings on the pane where the
profile waits to be installed. The line beneath it says what to expect: a
profile that needs an administrator to install, and titles shown as
<private> until then. The preferences the controller reads can be
supplied by a test.
@djp3

djp3 commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor Author

Okay, so I addressed this by making window titles private data in the unified log rather than plain text.

Each line keeps the process, window number and frame in the clear and carries the title as a private field, so log show prints title: <private> unless private data is enabled for Amethyst's subsystem on that Mac.

The opt-in is a configuration profile bundled with the app, scoped to Amethyst's subsystem only, offered by a button on the Debug tab; installing a profile needs an administrator and shows in System Settings, so a background process can't flip it the way it could a preference. --log is unchanged.

Screenshots and the code changes are isolated here with before-and-after output: djp3#2

Happy to fold it into this PR if the approach works for you (@ianyh ), or hear what you'd prefer instead.

@djp3

djp3 commented Nov 6, 2026

Copy link
Copy Markdown
Contributor Author

And if it's not obvious this has been very helpful for me to be able to see why some windows weren't tiling correctly.

djp3 added 3 commits November 9, 2026 10:40
While the profile that reveals window titles is installed, the Debug tab's
button reads Hide Window Titles in System Logs. It shows the steps for
removing the profile and offers to open the System Settings pane that
lists it. The button stays available with logging off, so the profile can
always be removed.

The app tells that the profile is installed from the logging options file
macOS keeps for the app's subsystem, and checks again whenever the app
comes back to the front.
Reveal Window Titles in System Logs now opens instructions in the same
form as the ones for removing the profile, naming the profile and the
steps in System Settings. The profile is handed to macOS only when Open
System Settings is chosen.
Store window titles as private data in the system log
@djp3

djp3 commented Nov 12, 2026

Copy link
Copy Markdown
Contributor Author

Merged in eaf7325, titles are private by default, with the profile button on the Debug tab for revealing and removing

@djp3
djp3 requested a review from ianyh November 15, 2026 00:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants