Created
March 15, 2016 21:53
-
-
Save johanatan/2e6540e9e3e198bac875 to your computer and use it in GitHub Desktop.
log-opts (bunyan helper)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn log-opts [logger level msg & params] | |
(let [amap (apply array-map params) | |
expected (count (re-seq #"%s|%d|%j" msg)) | |
args (flatten [amap msg (if (not (empty? amap)) (take expected (vals amap)))])] | |
(.apply (aget logger level) logger (clj->js (remove nil? args))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It can be used like so:
There can be more key/value pairs provided than placeholders in the formatted message (extras are just dropped as format params but still provided as part of
options
object for Bunyan to produce JSON from).