Skip to content

Commit

Permalink
Merge pull request #27 from rome-user/patch-log-expr
Browse files Browse the repository at this point in the history
Wrap `log-expr` in a conditional to assist DCE
  • Loading branch information
plexus authored Mar 24, 2023
2 parents 7c85abd + 8260a01 commit 109b82e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@

## Changed

- Modified an internal function so that code emitted by logging macros can be
DCE'd when the user disables logging.

# 1.2.164 (2022-11-25 / 9a89583)

## Added
Expand Down
15 changes: 8 additions & 7 deletions src/lambdaisland/glogi.clj
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
(defn- log-expr [form level keyvals]
(let [keyvals-map (apply array-map keyvals)
formatter (::formatter keyvals-map 'identity)]
`(log ~(::logger keyvals-map (str *ns*))
~level
(~formatter
~(-> keyvals-map
(dissoc ::logger)
(assoc :line (:line (meta form)))))
~(:exception keyvals-map))))
`(when ~(with-meta 'goog.debug.LOGGING_ENABLED {:tag 'boolean})
(log ~(::logger keyvals-map (str *ns*))
~level
(~formatter
~(-> keyvals-map
(dissoc ::logger)
(assoc :line (:line (meta form)))))
~(:exception keyvals-map)))))

(defmacro shout [& keyvals]
(log-expr &form :shout keyvals))
Expand Down

0 comments on commit 109b82e

Please sign in to comment.