Debugging
The log
Hazel logs to standard error.
- Nested, that's the terminal you started it from.
- Started with
hazel-session, from a display manager or a tty, it's~/.local/state/hazel/hazel.log. The session before is inhazel.log.old.
print in the config writes to the log, not to a terminal:
print("windows open:", wm.windows:count())INFO hazel::lua::runtime: print(): windows open: 2To see only the config's own lines and errors, start Hazel with RUST_LOG:
RUST_LOG=warn,hazel::lua=info hazelWhen the config has an error
A config that fails to load on save leaves the one that was running. At start, Hazel runs with no config until you save a fixed one. Either way the log has the error with the file and line:
ERROR hazel::core::lua_loading: Error loading Lua, keeping the current one: runtime error: /home/you/.config/hazel/main.lua:12: attempt to call a nil value (global 'bnid')Fix it and save again.
An error inside a handler, such as a key binding that calls something wrong, is logged each time the handler runs. The other handlers keep working.
hazel eval and hazel repl
hazel eval runs Lua inside the running config and prints what it returns. Run it in a terminal inside Hazel:
hazel eval 'wm.windows:count()'
hazel eval 'local ids = {} for _, window in ipairs(wm.windows:all()) do ids[#ids + 1] = window.app_id end return ids'It sees the same wm the config does, so it is the quickest way to find an app id for a window rule, an output's name, or what's in wm.store:
hazel eval 'wm.store'hazel repl is a prompt for the same, one chunk per line. A line that leaves a block open, like for i = 1, 3 do, waits for the rest.
- Locals don't carry over between chunks. Globals do, until the next reload.
printstill goes to the log. Return values instead.- Exit code 0 when the chunk ran, 1 on a Lua error, 2 when Hazel can't be reached.
The Socket page has the details, for scripts that talk to Hazel directly.
A handler that never ends
A loop that never finishes would freeze the whole desktop. Hazel stops any call into the config after 500000 Lua instructions and logs where it was:
ERROR hazel::lua::event_handler: Error details: key ran over its instruction budget of 500000 (wm.instruction_budget) and was stoppedThe handler stays registered and runs again next time. If something heavy really needs more, raise the limit at the top of main.lua:
wm.instruction_budget = 2000000See Instruction budget.
Screenshots of a nested Hazel
Nested, wm:screenshot writes a PNG of an output, which helps when you ask someone about a layout:
hazel eval 'wm:screenshot("/tmp/hazel.png")'On a tty it writes nothing. Use grim there.