Skip to content

district0x/district-ui-logging

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

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

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))

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]}))

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]}))

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])

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]}))

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")])

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

About

district UI module to set up devtools logging

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published