spacehammer icon indicating copy to clipboard operation
spacehammer copied to clipboard

Adjustable log levels

Open jaawerth opened this issue 5 months ago • 0 comments

This one's kind of out of left field, but since I already implemented it locally and find it pretty useful when debugging my spacehammer code without distractions, I figured I'd submit a PR and see if it was something you'd find potentially worth merging 😉. No harm if you close this in the event I'm the only one who finds it useful! Also, let me know if the impl + config field/format looks good or if you'd prefer something different. Thanks!

Usecase

There are times I've found troubleshooting things I do with my config a little unwieldy due to the log noise generated by the modal.fnl/apps.fnl debug logs. Since hammerspoon doesn't do anything special with the logger ID's in terms of managing id -> instance centrally, making each namespaced logger configurable would have required either exporting them each from their relevant modules or storing them in a container.

To simplify things, wrote a small state container for any instantiated loggers in lib/utils.fnl; just a weak-valued table for storing logger instances by ID and a function that either fetches an existing logger by name or instantiates and stores a new one, setting log level if provided.

I then proceeded to add support for a log-levels field in config, which is iterated at startup in core.fnl to override log levels:

;; disables debug output for modal/app focus change
(set config.log-levels {:apps.fnl :info :modal.fnl :info})

jaawerth avatar Jan 10 '24 21:01 jaawerth