Back
rolling-appender (clj)
(source)function
(rolling-appender & [{:keys [path pattern], :or {path "./timbre-rolling.log", pattern :daily}}])
Returns a Rolling file appender. Opts:
:path - logfile path.
:pattern - frequency of rotation, e/o {:daily :weekly :monthly}.
Examples
timbre
(ns taoensso.timbre.appenders.community.rolling-test
(:require
[clojure.test :refer [deftest is use-fixtures]]
[taoensso.timbre.appenders.community.rolling :as rolling])
(:import
(java.io File)
(java.nio.file Files)
(java.nio.file.attribute FileTime)
(java.time Instant)
(java.util Date TimeZone)))
(deftest rolling-appender-concurrency
(let [log-file (doto (File/createTempFile "timbre.rolling." ".log") (.deleteOnExit))]
(try
(let [rolling-appender (rolling/rolling-appender {:path (.getPath log-file) :pattern :daily})
now (Instant/parse "2021-11-04T00:00:00.00Z")
hour-ago (.minusSeconds now 3600)
rolled-over-log-file (File. (str log-file ".20211103"))
old-messages ["AAA" "BBB" "CCC"]
log-at #((:fn rolling-appender) {:instant %1 :output_ %2})]
;; Emulate log entries from an hour ago
(run! #(log-at (Date/from hour-ago) %) old-messages)