Advertisement
Guest User

Untitled

a guest
Jan 24th, 2021
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (defn- write-to-file [{:keys [output_] :as data} fname append? self]
  2.   (let [output (force output_)]
  3.     (try
  4.       (with-open [^java.io.BufferedWriter w (io/writer fname :append append?)]
  5.         (.write   w ^String output)
  6.         (.newLine w))
  7.  
  8.       (catch java.io.IOException e
  9.         (if (:spit-appender/retry? data)
  10.           (throw e) ; Unexpected error
  11.           (do
  12.             (io/make-parents fname)
  13.             (self (assoc data :spit-appender/retry? true))))))))
  14.  
  15. (defn my-appender [& [{:keys [fname append? locking?]
  16.                        :or   {fname "./timbre-spit.log"
  17.                               append?  true
  18.                               locking? true}}]]
  19.   (have? enc/nblank-str? fname)
  20.   {:enabled? true
  21.    :fn
  22.    (fn self [data]
  23.      (if locking?
  24.        (locking (Object.)
  25.          (write-to-file data fname append? self))
  26.        (write-to-file data fname append? self)))})
  27.  
  28. (alter-var-root
  29.  (var timbre/spit-appender)
  30.  my-appender)
  31.  
  32. (timbre/merge-config! {:appenders {:println {:enabled? false}
  33.                                    :spit (my-appender {:fname "/tmp/clojure-sample.out"})}})
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement