Liking cljdoc? Tell your friends :D

district-ui-logging

Build Status

Clojurescript re-mount module, that takes care of setting up timbre + cljs-devtools logging.

Installation

district-ui-logging is available as a Maven artifact from Clojars. The latest released version is: Clojars Project
To use the library include [district.ui.logging] in your CLJS file, where you use mount/start

Warning: district0x modules are still in early stages, therefore API can change in a future.

Usage

district.ui.logging

You can pass following args to logging component:

  • :level Min. level that should be logged.
  • :console? Pass true if you want to log into console as well.
  • :sentry sentry configuration options.

Log calls take the following arguments:

  • message (required) string with a human-readable message.
  • meta (optional) a map with context meta-data.
  • ns (optional) namespaced keyword for easy aggregating and searching. If none provided the module will try to inferr the namespace.

Example:

(ns my-district
  (:require [mount.core :as mount]
            [district.ui.logging]
            [taoensso.timbre :as log]))

  (-> (mount/with-args
        {:logging {:level :info
                   :console? true}})
    (mount/start))

  (log/error "foo" {:error (js/Error. "bad error")} ::error)
  ;; my-district/error:42 foo {:error "bad error"} :tests.all/error

sentry configuration options

In order to initialize sentry logging appender pass a map of options:

  • :dsn (required) tells the SDK where to send the events.
  • :min-level (optional) sets the minimal level of logging to sentry, :warn is the default. This setting overrides the timbres :level flag!

Example:

(-> (mount/with-args
      {:logging {:level :info
                 :console? true
                 :sentry {:dsn "https://4bb89c9cdae14444819ff0ac3bcba253@sentry.io/1306960"
                          :min-level :warn}}})
    (mount/start))

district.ui.logging.events

::info

This is an utility event which wraps the :log/info effect.

(ns my-district
  (:require [district.ui.logging.events :as logging]
            [re-frame.core :as re-frame]))

(re-frame/reg-event-fx
 ::my-event
 (fn []
   {:dispatch [::logging/info "success" {:foo "bar"} ::success]}))

:log/info

This is an effect which logs the success to the JS console.

(ns my-district
  (:require [district.ui.logging.events]
            [re-frame.core :as re-frame]))
            
(re-frame/reg-event-fx
 ::my-event
 (fn []
   {:log/info ["success" {:foo "bar"} ::success]}))

::warn

This is an utility event which wraps the :log/warn effect.

(ns my-district
  (:require [district.ui.logging.events :as logging]
            [re-frame.core :as re-frame]))

(re-frame/dispatch [::logging/warn "warning text" {:foo "bar"} ::here])

:log/warn

This is an effect which logs the success to the JS console.

(ns my-district
  (:require [district.ui.logging.events]
            [re-frame.core :as re-frame]))
            
(re-frame/reg-event-fx
 ::my-event
 (fn []
   {:log/warn ["warning text" {:foo "bar"} ::here]}))

::error

This is an utility event which wraps the :log/error effect.

(ns my-district
  (:require [district.ui.logging.events :as logging]
            [re-frame.core :as re-frame]))

(re-frame/dispatch [::logging/error "Unexpected Error" {:error (js/Error. "sad error") :foo "bar"} ::my-district])

You can also use pass only the JS Error:

(re-frame/dispatch [::logging/error (js/Error. "sad error")])

:log/error

This is an effect which logs the error to the JS console.

(ns my-district
  (:require [district.ui.logging.events]
            [re-frame.core :as re-frame]))
            
(re-frame/reg-event-fx
 ::my-event
 (fn []
   {:log/error ["Unexpected Error" {:foo "bar"} ::my-district]}))

Development

lein deps

# To run tests and rerun on changes
lein doo chrome tests

Can you improve this documentation? These fine people already did:
fbielejec, madvas & Filip Bielejec
Edit on GitHub

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close