Merge branch 'dev'

This commit is contained in:
Peter Taoussanis 2015-05-25 19:25:32 +07:00
commit e86e5c470c
4 changed files with 81 additions and 62 deletions

View File

@ -277,7 +277,7 @@ A simple **sampling profiler** is also available: `taoensso.timbre.profiling/sam
## Contact & contributing ## Contact & contributing
`lein start-dev` to get a (headless) development repl that you can connect to with [Cider][] (emacs) or your IDE. `lein start-dev` to get a (headless) development repl that you can connect to with [Cider][] (Emacs) or your IDE.
Please use the project's GitHub [issues page][] for project questions/comments/suggestions/whatever **(pull requests welcome!)**. Am very open to ideas if you have any! Please use the project's GitHub [issues page][] for project questions/comments/suggestions/whatever **(pull requests welcome!)**. Am very open to ideas if you have any!
@ -288,18 +288,16 @@ Otherwise reach me (Peter Taoussanis) at [taoensso.com][] or on [Twitter][]. Che
Copyright © 2012-2014 Peter Taoussanis. Distributed under the [Eclipse Public License][], the same as Clojure. Copyright © 2012-2014 Peter Taoussanis. Distributed under the [Eclipse Public License][], the same as Clojure.
[API docs]: <http://ptaoussanis.github.io/timbre/> [API docs]: http://ptaoussanis.github.io/timbre/
[CHANGELOG_]: <https://github.com/ptaoussanis/timbre/blob/master/CHANGELOG.md> [CHANGELOG]: https://github.com/ptaoussanis/timbre/releases
[CHANGELOG]: <https://github.com/ptaoussanis/timbre/releases> [other Clojure libs]: https://www.taoensso.com/clojure
[other Clojure libs]: <https://www.taoensso.com/clojure-libraries> [taoensso.com]: https://www.taoensso.com
[Twitter]: <https://twitter.com/ptaoussanis> [Twitter]: https://twitter.com/ptaoussanis
[SemVer]: <http://semver.org/> [issues page]: https://github.com/ptaoussanis/timbre/issues
[Break Version]: <https://github.com/ptaoussanis/encore/blob/master/BREAK-VERSIONING.md> [commit history]: https://github.com/ptaoussanis/timbre/commits/master
[Leiningen]: <http://leiningen.org/> [Break Version]: https://github.com/ptaoussanis/encore/blob/master/BREAK-VERSIONING.md
[CDS]: <http://clojure-doc.org/> [Leiningen]: http://leiningen.org/
[ClojureWerkz]: <http://clojurewerkz.org/> [Cider]: https://github.com/clojure-emacs/cider
[issues page]: <https://github.com/ptaoussanis/timbre/issues> [CDS]: http://clojure-doc.org/
[Cider]: <https://github.com/clojure-emacs/cider> [ClojureWerkz]: http://clojurewerkz.org/
[commit history]: <https://github.com/ptaoussanis/timbre/commits/master> [Eclipse Public License]: https://raw2.github.com/ptaoussanis/timbre/master/LICENSE
[taoensso.com]: <https://www.taoensso.com>
[Eclipse Public License]: <https://raw2.github.com/ptaoussanis/timbre/master/LICENSE>

View File

@ -12,21 +12,21 @@
:dependencies :dependencies
[[org.clojure/clojure "1.4.0"] [[org.clojure/clojure "1.4.0"]
[com.taoensso/encore "1.21.0"] [com.taoensso/encore "1.24.1"]
[io.aviso/pretty "0.1.16"]] [io.aviso/pretty "0.1.17"]]
:profiles :profiles
{;; :default [:base :system :user :provided :dev] {;; :default [:base :system :user :provided :dev]
:server-jvm {:jvm-opts ^:replace ["-server"]} :server-jvm {:jvm-opts ^:replace ["-server"]}
:1.5 {:dependencies [[org.clojure/clojure "1.5.1"]]} :1.5 {:dependencies [[org.clojure/clojure "1.5.1"]]}
:1.6 {:dependencies [[org.clojure/clojure "1.6.0"]]} :1.6 {:dependencies [[org.clojure/clojure "1.6.0"]]}
:test {:dependencies [[expectations "2.0.13"] :test {:dependencies [[expectations "2.1.0"]
[org.clojure/test.check "0.7.0"] [org.clojure/test.check "0.7.0"]
[org.clojure/tools.logging "0.3.1"] [org.clojure/tools.logging "0.3.1"]
;; Appender dependencies ;; Appender dependencies
[com.taoensso/nippy "2.7.1"] [com.taoensso/nippy "2.8.0"]
[com.taoensso/carmine "2.9.0"] [com.taoensso/carmine "2.9.2"]
[com.draines/postal "1.11.3"] [com.draines/postal "1.11.3"]
[irclj "0.5.0-alpha4"]] [irclj "0.5.0-alpha4"]]
:plugins [[lein-expectations "0.0.8"] :plugins [[lein-expectations "0.0.8"]
@ -34,8 +34,8 @@
:dev :dev
[:1.6 :test [:1.6 :test
{:dependencies [] {:dependencies []
:plugins [[lein-ancient "0.5.4"] :plugins [[lein-ancient "0.6.4"]
[codox "0.8.10"]]}]} [codox "0.8.11"]]}]}
:test-paths ["test" "src"] :test-paths ["test" "src"]

View File

@ -4,7 +4,8 @@
[io.aviso.exception :as aviso-ex] [io.aviso.exception :as aviso-ex]
[taoensso.encore :as enc]) [taoensso.encore :as enc])
(:import [java.util Date Locale] (:import [java.util Date Locale]
[java.text SimpleDateFormat])) [java.text SimpleDateFormat]
[java.io File]))
;;;; Encore version check ;;;; Encore version check
@ -96,6 +97,27 @@
(:current-level config) (:current-level config)
@level-atom)))) @level-atom))))
;;;;
(def ^:private get-hostname
(enc/memoize* 60000
(fn []
(->
(future ; Android doesn't like this on the main thread
(try (.. java.net.InetAddress getLocalHost getHostName)
(catch java.net.UnknownHostException _
"UnknownHost")))
(deref 5000 "UnknownHost")))))
(def ^:private ensure-spit-dir-exists!
(enc/memoize* 60000
(fn [fname]
(when-not (str/blank? fname)
(let [file (File. ^String fname)
dir (.getParentFile (.getCanonicalFile file))]
(when-not (.exists dir)
(.mkdirs dir)))))))
;;;; Default configuration and appenders ;;;; Default configuration and appenders
(defn default-fmt-output-fn (defn default-fmt-output-fn
@ -186,7 +208,8 @@
:min-level nil :enabled? false :async? false :rate-limit nil :min-level nil :enabled? false :async? false :rate-limit nil
:fn (fn [{:keys [ap-config output]}] ; Can use any appender args :fn (fn [{:keys [ap-config output]}] ; Can use any appender args
(when-let [filename (:spit-filename ap-config)] (when-let [filename (:spit-filename ap-config)]
(try (spit filename (str output "\n") :append true) (try (ensure-spit-dir-exists! filename)
(spit filename (str output "\n") :append true)
(catch java.io.IOException _))))}}}) (catch java.io.IOException _))))}}})
(enc/defonce* config (atom example-config)) (enc/defonce* config (atom example-config))
@ -259,16 +282,6 @@
(fn [apfn-args] ; Runtime: (fn [apfn-args] ; Runtime:
(send-off agent (fn [_] (apfn apfn-args))))))))))) (send-off agent (fn [_] (apfn apfn-args)))))))))))
(def ^:private get-hostname
(enc/memoize* 60000
(fn []
(->
(future ; Android doesn't like this on the main thread
(try (.. java.net.InetAddress getLocalHost getHostName)
(catch java.net.UnknownHostException _
"UnknownHost")))
(deref 5000 "UnknownHost")))))
(defn- wrap-appender-juxt (defn- wrap-appender-juxt
"Wraps compile-time appender juxt with additional runtime capabilities "Wraps compile-time appender juxt with additional runtime capabilities
(incl. middleware) controlled by compile-time config. Like `wrap-appender-fn` (incl. middleware) controlled by compile-time config. Like `wrap-appender-fn`

View File

@ -2,32 +2,40 @@
"Android LogCat appender. Depends on the android runtime. This is a "Android LogCat appender. Depends on the android runtime. This is a
configuration for the timbre logging library" configuration for the timbre logging library"
{:author "Adam Clements"} {:author "Adam Clements"}
(:require [taoensso.timbre :as timbre])) (:require [taoensso.timbre :as timbre]
clojure.string))
(defn make-logcat-appender
"Returns an appender that writes to Android LogCat. Obviously only works if
running within the Android runtime (device or emulator). You may want to
disable std-out to prevent printing nested timestamps, etc."
[& [appender-opts make-opts]]
(let [default-appender-opts {:enabled? true
:min-level :debug}]
(merge default-appender-opts appender-opts
{:fn (fn [{:keys [level ns throwable message]}]
(let [output (format "%s %s - %s" timestamp
(-> level name clojure.string/upper-case)
(or message ""))]
(if throwable
(case level
:trace (android.util.Log/d ns output throwable)
:debug (android.util.Log/d ns output throwable)
:info (android.util.Log/i ns output throwable)
:warn (android.util.Log/w ns output throwable)
:error (android.util.Log/e ns output throwable)
:fatal (android.util.Log/e ns output throwable)
:report (android.util.Log/i ns output throwable))
(case level
:trace (android.util.Log/d ns output)
:debug (android.util.Log/d ns output)
:info (android.util.Log/i ns output)
:warn (android.util.Log/w ns output)
:error (android.util.Log/e ns output)
:fatal (android.util.Log/e ns output)
:report (android.util.Log/i ns output)))))})))
(def logcat-appender (def logcat-appender
{:doc (str "Appends to Android logcat. Obviously only works if " "DEPRECATED: Use `make-logcat-appender` instead."
"running within the Android runtime (device or emulator)." (make-logcat-appender))
"You may want to disable std-out to prevent printing nested "
"timestamps, etc.")
:min-level :debug
:enabled? true
:prefix-fn :ns
:fn (fn [{:keys [level prefix throwable message]}]
(if throwable
(case level
:trace (android.util.Log/d prefix message throwable)
:debug (android.util.Log/d prefix message throwable)
:info (android.util.Log/i prefix message throwable)
:warn (android.util.Log/w prefix message throwable)
:error (android.util.Log/e prefix message throwable)
:fatal (android.util.Log/e prefix message throwable)
:report (android.util.Log/i prefix message throwable))
(case level
:trace (android.util.Log/d prefix message)
:debug (android.util.Log/d prefix message)
:info (android.util.Log/i prefix message)
:warn (android.util.Log/w prefix message)
:error (android.util.Log/e prefix message)
:fatal (android.util.Log/e prefix message)
:report (android.util.Log/i prefix message))))})