Skip to content

Commit

Permalink
bump yeller dependencies, move to multi segment ns
Browse files Browse the repository at this point in the history
  • Loading branch information
tcrayford committed Jun 21, 2015
1 parent 2e3d72c commit e3a608d
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 9 deletions.
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ Leiningen:
First initialize the Yeller timbre appender:

```clojure
(require '[yeller-timbre-appender])
(require '[yeller.timbre-appender])
(timbre/set-config! [:appenders :yeller]
(yeller-timbre-appender/make-yeller-appender
(yeller.timbre-appender/make-yeller-appender
{:token "YOUR TOKEN HERE" :environment "production"}))
```

Expand All @@ -30,9 +30,9 @@ Also, if you have an existing Yeller client, you can pass it in with
existing yeller client instance and don't want two instances of it:

```clojure
(require '[yeller-timbre-appender]
'[yeller-clojure-client])
(def client (yeller-clojure-client/client {:token "YOUR TOKEN HERE" :environment "production"})
(require '[yeller.timbre-appender]
'[yeller.clojure.client])
(def client (yeller.clojure.client/client {:token "YOUR TOKEN HERE" :environment "production"})
(timbre/set-config! [:appenders :yeller]
(yeller-timbre-appender/make-yeller-appender
{:yeller/client client}))
Expand Down Expand Up @@ -73,10 +73,10 @@ For example, to use the timbre error in a ring middleware:
(timbre/error t {:url (:uri req)})))))
```

The map argument takes the same set of keys the yeller clojure client takes as its second argument. See the docstring on `yeller-clojure-client/report`:
The map argument takes the same set of keys the yeller clojure client takes as its second argument. See the docstring on `yeller.clojure.client/report`:

```clojure
(doc yeller-clojure-client/report)
(doc yeller.clojure.client/report)
```


Expand Down
4 changes: 2 additions & 2 deletions project.clj
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
(defproject yeller-timbre-appender "0.5.0"
(defproject yeller-timbre-appender "1.2.0"
:description "A timbre appender that sends exceptions to yellerapp.com"
:url "https://github.com/yeller/yeller-timbre-appender"
:license {:name "Eclipse Public License"
:url "http://www.eclipse.org/legal/epl-v10.html"}
:dependencies [[org.clojure/clojure "1.6.0"]
[com.taoensso/timbre "3.2.1"]
[yeller-clojure-client "0.5.0"]])
[yeller-clojure-client "1.2.0"]])
74 changes: 74 additions & 0 deletions src/yeller/timbre_appender.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
(ns yeller.timbre-appender
(:require [yeller-clojure-client :as yeller-client]))

(defn create-client [options]
(if-let [client (:yeller/client options)]
client
(yeller-client/client options)))

(defn extract-ex-data [throwable]
(if-let [data (ex-data throwable)]
{:ex-data data}
{}))

(defn extract-arg-data [raw-args]
(if (map? (first raw-args))
(first raw-args)
{}))

(defn extract-data [throwable raw-args]
(let [arg-data (extract-arg-data raw-args)
ex-data (extract-ex-data throwable)]
(merge
arg-data
{:custom-data (merge ex-data (:custom-data arg-data {}))})))

(defn make-yeller-appender
"Create a Yeller timbre appender.
(make-yeller-appender {:token \"YOUR API TOKEN HERE\"})
Required options:
either:
:token \"your api token here\"
OR
:yeller/client an-existing-yeller-client
The second option is for when you already use yeller somewhere else and
only want one client in the codebase.
Optional:
:environment \"production\" ; the name of the environment the app runs in
(note that exceptions reported in \"development\" or \"test\" environments
are ignored) (defaults to \"production\"
:application-packages [\"com.myapp\"] : the name(s) of the root packages your
app runs in. Defaults to reading out of project.clj (both locally and in an uberjar settings). This lets the web ui display stacktrace lines only from the app by default (and hide those from libraries and from clojure itself).
Optionally takes an additional map (as a first argument) which gets merged as timbre options:
(make-yeller-appender
{:min-level :error, :enabled? true}
{:token \"your token here\"})"
([options] (make-yeller-appender {} options))
([timbre-options options]
(assert (or (string? (:token options))
(:yeller/client options)) "make-yeller-appender requires a :token or a :yeller/client")
(let [with-default (merge {:environment "production"} options)
client (create-client with-default)]
(merge
{:doc "A timbre appender that sends errors to yellerapp.com"
:min-level :warn
:enabled? true
:async? true
:rate-limit nil
:fn (fn [args]
(let [throwable (:throwable args)
data (extract-data throwable (:args args))]
(if (and (:error? args)
throwable)
(yeller-client/report
client
throwable
(merge {:environment (:environment with-default "production")
:location (:ns args)}
data)))))}
timbre-options))))

(comment
;; for repl testing
(do (require '[taoensso.timbre :as timbre]) (require '[yeller-timbre-appender :reload true]) (timbre/set-config! [:appenders :yeller] (yeller-timbre-appender/make-yeller-appender {:token "YOUR TOKEN HERE" :environment "timbre-test"})) (dotimes [_ 1] (timbre/error (ex-info "lol" {:foo 1}) {:custom-data {:params {:user-id 1}}})))
)

0 comments on commit e3a608d

Please sign in to comment.