mirror of https://github.com/status-im/timbre.git
Merge branch 'dev'
This commit is contained in:
commit
82c0900aee
|
@ -1,3 +1,10 @@
|
||||||
|
## v3.1.4 / 2014 Mar 13
|
||||||
|
|
||||||
|
* NEW: Add `profiling/p*` macro.
|
||||||
|
* CHANGE: Include `p`, `p*` in `refer-timbre` imports.
|
||||||
|
* FIX: rotor appender not rotating (iantruslove, kurtharriger).
|
||||||
|
|
||||||
|
|
||||||
## v3.1.3 / 2014 Mar 11
|
## v3.1.3 / 2014 Mar 11
|
||||||
|
|
||||||
* FIX: profiling id namespacing.
|
* FIX: profiling id namespacing.
|
||||||
|
|
|
@ -42,7 +42,8 @@ The `refer-timbre` call is a convenience fn that executes:
|
||||||
:refer (log trace debug info warn error fatal report
|
:refer (log trace debug info warn error fatal report
|
||||||
logf tracef debugf infof warnf errorf fatalf reportf
|
logf tracef debugf infof warnf errorf fatalf reportf
|
||||||
spy logged-future with-log-level sometimes)])
|
spy logged-future with-log-level sometimes)])
|
||||||
(require '[taoensso.timbre.profiling :as profiling :refer (pspy pspy* profile defnp)])
|
(require '[taoensso.timbre.profiling :as profiling
|
||||||
|
:refer (pspy pspy* profile defnp p p*)])
|
||||||
```
|
```
|
||||||
|
|
||||||
### Logging
|
### Logging
|
||||||
|
|
|
@ -497,7 +497,8 @@
|
||||||
logf tracef debugf infof warnf errorf fatalf reportf
|
logf tracef debugf infof warnf errorf fatalf reportf
|
||||||
spy logged-future with-log-level sometimes)])
|
spy logged-future with-log-level sometimes)])
|
||||||
(require
|
(require
|
||||||
'[taoensso.timbre.profiling :as profiling :refer (pspy pspy* profile defnp)])"
|
'[taoensso.timbre.profiling :as profiling
|
||||||
|
:refer (pspy pspy* profile defnp p p*)])"
|
||||||
[]
|
[]
|
||||||
(require
|
(require
|
||||||
'[taoensso.timbre :as timbre
|
'[taoensso.timbre :as timbre
|
||||||
|
@ -505,7 +506,8 @@
|
||||||
logf tracef debugf infof warnf errorf fatalf reportf
|
logf tracef debugf infof warnf errorf fatalf reportf
|
||||||
spy logged-future with-log-level sometimes)])
|
spy logged-future with-log-level sometimes)])
|
||||||
(require
|
(require
|
||||||
'[taoensso.timbre.profiling :as profiling :refer (pspy pspy* profile defnp)]))
|
'[taoensso.timbre.profiling :as profiling
|
||||||
|
:refer (pspy pspy* profile defnp p p*)]))
|
||||||
|
|
||||||
;;;; Deprecated
|
;;;; Deprecated
|
||||||
|
|
||||||
|
|
|
@ -37,20 +37,13 @@
|
||||||
the naming of archived logs."
|
the naming of archived logs."
|
||||||
[basepath max-count]
|
[basepath max-count]
|
||||||
(let [abs-path (-> basepath io/file (.getAbsolutePath))
|
(let [abs-path (-> basepath io/file (.getAbsolutePath))
|
||||||
logs (->> basepath
|
logs (-> basepath matching-files sort)
|
||||||
matching-files
|
[logs-to-rotate logs-to-delete] (split-at max-count logs)]
|
||||||
(take max-count)
|
(doseq [log-to-delete logs-to-delete]
|
||||||
(map (fn [^File x] (.getAbsolutePath x)))
|
(io/delete-file log-to-delete))
|
||||||
sort
|
(doseq [[^File log-file n]
|
||||||
reverse)
|
(reverse (map vector logs-to-rotate (iterate inc 1)))]
|
||||||
num-logs (count logs)
|
(.renameTo log-file (io/file (format "%s.%03d" abs-path n))))))
|
||||||
overflow? (> num-logs max-count)]
|
|
||||||
(when overflow?
|
|
||||||
(io/delete-file (first logs)))
|
|
||||||
(loop [[log & more] (if overflow? (rest logs) logs) n num-logs]
|
|
||||||
(when log
|
|
||||||
(.renameTo (io/file log) (io/file (format "%s.%03d" abs-path n)))
|
|
||||||
(recur more (dec n))))))
|
|
||||||
|
|
||||||
(defn appender-fn [{:keys [ap-config output]}]
|
(defn appender-fn [{:keys [ap-config output]}]
|
||||||
(let [{:keys [path max-size backlog]
|
(let [{:keys [path max-size backlog]
|
||||||
|
|
|
@ -28,6 +28,7 @@
|
||||||
[id & body] `(pspy* ~id (fn [] ~@body)))
|
[id & body] `(pspy* ~id (fn [] ~@body)))
|
||||||
|
|
||||||
(defmacro p [id & body] `(pspy ~id ~@body)) ; Alias
|
(defmacro p [id & body] `(pspy ~id ~@body)) ; Alias
|
||||||
|
(defmacro p* [id & body] `(pspy* ~id ~@body)) ; Alias
|
||||||
|
|
||||||
(comment
|
(comment
|
||||||
(time (dotimes [_ 1000000])) ; ~20ms
|
(time (dotimes [_ 1000000])) ; ~20ms
|
||||||
|
|
|
@ -0,0 +1,39 @@
|
||||||
|
(ns taoensso.timbre.tests.appenders.rotor
|
||||||
|
{:author "Ian Truslove, Kurt Harriger"}
|
||||||
|
(:require [taoensso.timbre.appenders.rotor :as rotor :refer :all]
|
||||||
|
[clojure.test :refer :all]
|
||||||
|
[clojure.java.io :refer [file]]))
|
||||||
|
|
||||||
|
(defn with-temp-dir-containing-log-files
|
||||||
|
"Call f with the temp directory name, that directory having n log
|
||||||
|
files created within it"
|
||||||
|
[n f]
|
||||||
|
(let [tmp-dir (java.io.File/createTempFile "test" "")
|
||||||
|
log-file-basename "log"
|
||||||
|
log-files (into [log-file-basename]
|
||||||
|
(map #(format "%s.%03d" log-file-basename %) (range 1 n)))]
|
||||||
|
(.delete tmp-dir)
|
||||||
|
(.mkdirs tmp-dir)
|
||||||
|
(doseq [filename log-files] (.createNewFile (file tmp-dir filename)))
|
||||||
|
(try
|
||||||
|
(f (.getAbsolutePath (file tmp-dir (first log-files))))
|
||||||
|
(finally
|
||||||
|
(doseq [filename log-files] (.delete (file tmp-dir filename)))
|
||||||
|
(.delete (file tmp-dir))))))
|
||||||
|
|
||||||
|
(deftest test-rotor
|
||||||
|
(testing "rotating logs"
|
||||||
|
(testing "when rotating with a full backlog of files, the last should be deleted"
|
||||||
|
(with-temp-dir-containing-log-files 5
|
||||||
|
(fn [basepath]
|
||||||
|
(#'rotor/rotate-logs basepath 2)
|
||||||
|
(is (not (.exists (file (str basepath))))
|
||||||
|
"log should have been rotated to log.001")
|
||||||
|
(is (.exists (file (str basepath ".001")))
|
||||||
|
"log.001 should remain")
|
||||||
|
(is (.exists (file (str basepath ".002")))
|
||||||
|
"log.002 should remain")
|
||||||
|
(is (not (.exists (file (str basepath ".003"))))
|
||||||
|
"log.003 should be deleted because it is past the max-count threshold")
|
||||||
|
(is (not (.exists (file (str basepath ".004"))))
|
||||||
|
"log.004 should be deleted because it is past the max-count threshold"))))))
|
|
@ -2,7 +2,7 @@
|
||||||
(:require [expectations :as test :refer :all]
|
(:require [expectations :as test :refer :all]
|
||||||
[taoensso.timbre :as timbre]))
|
[taoensso.timbre :as timbre]))
|
||||||
|
|
||||||
(timbre/refer-timbre)
|
;; (timbre/refer-timbre)
|
||||||
|
|
||||||
(comment (test/run-tests '[taoensso.timbre.tests.main]))
|
(comment (test/run-tests '[taoensso.timbre.tests.main]))
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue