Last active
March 14, 2019 10:31
-
-
Save caskolkm/39d823f5bac7051d3062 to your computer and use it in GitHub Desktop.
Simple Clojurescript logging using Google Closure logging tools, now in cljc :)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns app.logging | |
(:refer-clojure :exclude [time]) | |
(:require #?(:clj [clojure.tools.logging :as log] | |
:cljs [goog.log :as glog])) | |
#?(:cljs (:import goog.debug.Console))) | |
#?(:cljs | |
(def logger | |
(glog/getLogger "app"))) | |
#?(:cljs | |
(def levels {:severe goog.debug.Logger.Level.SEVERE | |
:warning goog.debug.Logger.Level.WARNING | |
:info goog.debug.Logger.Level.INFO | |
:config goog.debug.Logger.Level.CONFIG | |
:fine goog.debug.Logger.Level.FINE | |
:finer goog.debug.Logger.Level.FINER | |
:finest goog.debug.Logger.Level.FINEST})) | |
#?(:cljs | |
(defn log-to-console! [] | |
(.setCapturing (goog.debug.Console.) true))) | |
#?(:cljs | |
(defn set-level! [level] | |
(.setLevel logger (get levels level (:info levels))))) | |
(defn fmt [msgs] | |
(apply str (interpose " " (map pr-str msgs)))) | |
(defn info [& s] | |
(let [msg (fmt s)] | |
#?(:clj (log/info msg) | |
:cljs (glog/info logger msg)))) | |
(defn debug [& s] | |
(let [msg (fmt s)] | |
#?(:clj (log/debug msg) | |
:cljs (glog/fine logger msg)))) | |
(defn error [& s] | |
(let [msg (fmt s)] | |
#?(:clj (log/error msg) | |
:cljs (glog/error logger msg)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Nice! It would be great the other way around,
clojure.tools.logging
including the Closure logging and ClojureScript.