Skip to content

Instantly share code, notes, and snippets.

@AdamClements
Last active December 27, 2015 01:59
Show Gist options
  • Save AdamClements/7248537 to your computer and use it in GitHub Desktop.
Save AdamClements/7248537 to your computer and use it in GitHub Desktop.
A Logcat appender for timbre
(def logcat-appender
{:doc (str "Appends to android logcat. Obviously only works if "
"running within the android runtime, either on a device "
"or an emulator")
:min-level :debug
:enabled? true
:async? false
:limit-per-msecs nil
:prefix-fn :ns
:fn (fn [{:keys [level prefix throwable message]}]
(if throwable
(condp = level
:error (android.util.Log/e prefix message throwable)
:info (android.util.Log/i prefix message throwable)
:warn (android.util.Log/w prefix message throwable)
:debug (android.util.Log/d prefix message throwable))
(condp = level
:error (android.util.Log/e prefix message)
:info (android.util.Log/i prefix message)
:warn (android.util.Log/w prefix message)
:debug (android.util.Log/d prefix message))))})
;;; Workaround for network on main thread issue:
(alter-var-root (var taoensso.timbre/get-hostname) (fn [old] (constantly "AndroidHost")))
;;; Enable logcat appender and disable stdout (as it gets printed to
;;; logcat too but noisily)
(timbre/set-config! [:appenders :lolcat] logcat-appender)
(timbre/set-config! [:appenders :standard-out :enabled?] false)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment