-
Notifications
You must be signed in to change notification settings - Fork 71
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adjustable log levels #189
base: master
Are you sure you want to change the base?
Conversation
State manager for loggers, by id. The primary usecase is for users to override the log level of a given logger id using a central location to store them by ID. Table is weak-valued so loggers can be cleaned up when they have no remaining references outside of the container. Invoking the table as a function ala `(logger "logger-id" ?some-level)` allows users to fetch a logger with a given ID if it's already been instantiated, otherwise creating and storing a new one by passing arguments to `hs.logger.new`
Uses the logger helper in lib/utils.fnl, iterating k-v pairs found in `config.log-levels` of the form `{logger-id log-level}` to set them.
@@ -6,4 +8,20 @@ | |||
(let [filter (hs.window.filter.new)] | |||
(: filter :setAppFilter :Emacs {:allowRoles [:AXUnknown :AXStandardWindow :AXDialog :AXSystemDialog]}))) | |||
|
|||
{:global-filter global-filter} | |||
(fn get-or-add-logger [loggers id ?level] | |||
"If (. loggers id) exists, returns it; otherwise instaniates & stores a new one. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo instantiates
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like this, will have to test it out.
log))) | ||
|
||
;; Weak-valued table to store instantiated loggers by ID. Can be called as a | ||
;; function to create & store a new instance, optioanlly with provided log level |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo optionally
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 incore.fnl
to override log levels: