Extract logging into common lib
This commit is contained in:
parent
1b60bd014a
commit
9868cc3612
@ -1,16 +1,11 @@
|
||||
(ns looped-in.content
|
||||
(:require-macros [cljs.core.async.macros :refer [go]])
|
||||
(:require [ajax.core :refer [GET]]
|
||||
[cljs.core.async :as async :refer [chan <! >!]]))
|
||||
[cljs.core.async :as async :refer [chan <! >!]]
|
||||
[looped-in.logging :as log]))
|
||||
|
||||
(enable-console-print!)
|
||||
|
||||
(defn log [& args]
|
||||
(apply js/console.log "[Looped In]" args))
|
||||
|
||||
(defn error [& args]
|
||||
(apply js/console.error "[Looped In]" args))
|
||||
|
||||
(defn fetch-submission
|
||||
"Fetches submissions from Hacker News by `url`"
|
||||
[url]
|
||||
@ -20,7 +15,7 @@
|
||||
"hitsPerPage" 1000
|
||||
"restrictSearchableAttributes" "url"}
|
||||
:handler (fn [res] (go (>! response-chan res)))
|
||||
:error-handler (fn [err] (error "Error fetching HN stories:"
|
||||
:error-handler (fn [err] (log/error "Error fetching HN stories:"
|
||||
(clj->js err)))})
|
||||
response-chan))
|
||||
|
||||
@ -30,7 +25,7 @@
|
||||
;; request and this method for 5 minutes using localStorage
|
||||
[url response]
|
||||
(let [{:strs [hits]} response]
|
||||
(log "response" response)
|
||||
(log/debug "response" response)
|
||||
(filter #(= (get % "url") url) hits)))
|
||||
|
||||
(defn sort-hits
|
||||
@ -46,7 +41,7 @@
|
||||
(defn handle-hits
|
||||
"Handles a filtered response"
|
||||
[hits]
|
||||
(log (clj->js hits))
|
||||
(log/debug (clj->js hits))
|
||||
(let [num-comments (total-num-comments hits)]
|
||||
(-> js/browser
|
||||
(.-runtime)
|
||||
|
13
src_cljs/looped_in/logging.cljs
Normal file
13
src_cljs/looped_in/logging.cljs
Normal file
@ -0,0 +1,13 @@
|
||||
(ns looped-in.logging)
|
||||
|
||||
(defn info [& args]
|
||||
(apply js/console.info "[Looped In]" args))
|
||||
|
||||
(defn error [& args]
|
||||
(apply js/console.error "[Looped In]" args))
|
||||
|
||||
(defn debug [& args]
|
||||
(apply js/console.debug "[Looped In]" args))
|
||||
|
||||
(defn warn [& args]
|
||||
(apply js/console.warn "[Looped In]" args))
|
Loading…
Reference in New Issue
Block a user