Skip to content
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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adjustable log levels #189

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion core.fnl
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
:reduce reduce
:split split
:some some} (require :lib.functional))
(local {: logger} (require :lib.utils))
(local atom (require :lib.atom))
(require-macros :lib.macros)
(require-macros :lib.advice.macros)
Expand All @@ -24,7 +25,7 @@
(local customdir (.. homedir "/.spacehammer"))
(tset fennel :path (.. customdir "/?.fnl;" fennel.path))

(local log (hs.logger.new "\tcore.fnl\t" "debug"))
(local log (logger "\tcore.fnl\t" "debug"))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; defaults
Expand Down Expand Up @@ -236,3 +237,6 @@ Returns nil. This function causes side-effects.
{path (module.init config)})))
(reduce #(merge $1 $2) {})))

;; override log level for named loggers in config
(each [logger-id level (pairs (or config.log-levels {}))]
(logger logger-id level))
3 changes: 2 additions & 1 deletion lib/apps.fnl
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ This module works mechanically similar to lib/modal.fnl.
:bind-keys bind-keys}
(require :lib.bind))
(local lifecycle (require :lib.lifecycle))
(local {: logger} (require :lib.utils))


(local log (hs.logger.new "apps.fnl" "debug"))
(local log (logger "apps.fnl" "debug"))

(local actions (atom.new nil))
;; Create a dynamic var to hold an accessible instance of our finite state
Expand Down
3 changes: 2 additions & 1 deletion lib/bind.fnl
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
: map
: split}
(require :lib.functional))
(local {: logger} (require :lib.utils))

(local log (hs.logger.new "bind.fnl" "debug"))
(local log (logger "bind.fnl" "debug"))

(fn do-action
[action args]
Expand Down
3 changes: 2 additions & 1 deletion lib/lifecycle.fnl
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
(local {: do-action} (require :lib.bind))
(local log (hs.logger.new "lifecycle.fnl" "debug"))
(local {: logger} (require :lib.utils))
(local log (logger "lifecycle.fnl" "debug"))


"
Expand Down
3 changes: 2 additions & 1 deletion lib/modal.fnl
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,15 @@ switching menus in one place which is then powered by config.fnl.
: map
: merge}
(require :lib.functional))
(local {: logger} (require :lib.utils))
(local {:align-columns align-columns}
(require :lib.text))
(local {:action->fn action->fn
:bind-keys bind-keys}
(require :lib.bind))
(local lifecycle (require :lib.lifecycle))

(local log (hs.logger.new "modal.fnl" "debug"))
(local log (logger "modal.fnl" "debug"))
(var fsm nil)
(local default-style {:textFont "Menlo"
:textSize 16
Expand Down
4 changes: 2 additions & 2 deletions lib/statemachine.fnl
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ the next transition.
: last
: merge
: slice} (require :lib.functional))

(local {: logger} (require :lib.utils))

(fn update-state
[fsm state]
Expand Down Expand Up @@ -124,7 +124,7 @@ the next transition.
(let [fsm {:state (atom.new {:current-state template.state.current-state :context template.state.context})
:states template.states
:subscribers (atom.new {})
:log (if template.log (hs.logger.new template.log "info"))}]
:log (if template.log (logger template.log "info"))}]
; Add methods
(tset fsm :get-state (partial get-state fsm))
(tset fsm :send (partial send fsm))
Expand Down
20 changes: 19 additions & 1 deletion lib/utils.fnl
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
(local fennel (require :fennel))

(fn global-filter
[]
"
Expand All @@ -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.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo instantiates

If ?level is provided, sets it on the new or existing hs.logger instance.
`loggers` is expected to be a weak-valued table."
(case (. loggers id)
log (do (when ?level (log.setLogLevel ?level))
log)
_ (let [log (hs.logger.new id ?level)]
(tset loggers id log)
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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo optionally

(local logger (setmetatable {} {:__mode :v :__call get-or-add-logger}))

{:global-filter global-filter
: logger}
4 changes: 3 additions & 1 deletion vim.fnl
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@
: map
: noop
: some} (require :lib.functional))
(local {: logger} (require :lib.utils))

(local statemachine (require :lib.statemachine))
(local {:bind-keys bind-keys} (require :lib.bind))
(local log (hs.logger.new "vim.fnl" "debug"))
(local log (logger "vim.fnl" "debug"))

"
Create a vim mode for any text editor!
Expand Down