Back

log! (clj)

(source)

macro

(log! {:as opts, :keys [loc level msg-type args vargs config ?err ?base-data spying?], :or {config (quote clojure.core/*config*), ?err :auto}}) (log! level msg-type args & [opts])
Core low-level log macro. Useful for tooling/library authors, etc. * `level` - must eval to a valid logging level * `msg-type` - must eval to e/o #{:p :f nil} * `args` - arguments seq (ideally vec) for logging call * `opts` - ks e/o #{:config ?err ?base-data spying? :?ns-str :?file :?line :?column} Supports compile-time elision when compile-time const vals provided for `level` and/or `?ns-str`. Logging wrapper examples: (defn log-wrapper-fn [& args] (timbre/log! :info :p args)) (defmacro log-wrapper-macro [& args] (timbre/keep-callsite `(timbre/log! :info :p ~args)))

Examples

timbre
(ns taoensso.timbre-tests
  (:require
   [clojure.test    :as test :refer [deftest testing is]]
   [taoensso.encore :as enc]
   [taoensso.timbre :as timbre])

       (timbre/log! ~level :p ~args {:loc {:ns ~ns}})
       (deref (:data_ appender#)))))
furkan3ayraktar/clojure-polylith-realworld-example-app
(ns clojure.realworld.log.core
  (:require [taoensso.timbre :as timbre]))

(defmacro info [args]
  `(timbre/log! :info :p ~args))

(defmacro warn [args]
  `(timbre/log! :warn :p ~args))

(defmacro error [args]
  `(timbre/log! :error :p ~args))
yapsterapp/a-frame
(ns a-frame.log
  "overrides of the timbre logging macros
   which set a context from an a-frame
   interceptor-context key, or app-ctx key"
  #?(:cljs (:require-macros [a-frame.log]))
  (:require
   [taoensso.timbre :as timbre]
   [a-frame.schema :as af.schema]))

;;; Log using print-style args
(defmacro log*
  [context-src config level & args]
  `(with-a-frame-log-context ~context-src
     (timbre/log! ~level  :p ~args ~{:?line (@#'timbre/fline &form) :config config})))

(defmacro log
  [context-src level & args]
  `(with-a-frame-log-context ~context-src
     (timbre/log! ~level  :p ~args ~{:?line (@#'timbre/fline &form)})))

(defmacro trace
  [context-src & args]
  `(with-a-frame-log-context ~context-src
     (timbre/log! :trace  :p ~args ~{:?line (@#'timbre/fline &form)})))

(defmacro debug
  [context-src & args]
  `(with-a-frame-log-context ~context-src
     (timbre/log! :debug  :p ~args ~{:?line (@#'timbre/fline &form)})))

(defmacro info
  [context-src & args]
  `(with-a-frame-log-context ~context-src
     (timbre/log! :info   :p ~args ~{:?line (@#'timbre/fline &form)})))

(defmacro warn
  [context-src & args]
  `(with-a-frame-log-context ~context-src
     (timbre/log! :warn   :p ~args ~{:?line (@#'timbre/fline &form)})))

(defmacro error
  [context-src & args]
  `(with-a-frame-log-context ~context-src
     (timbre/log! :error  :p ~args ~{:?line (@#'timbre/fline &form)})))

(defmacro fatal
  [context-src & args]
  `(with-a-frame-log-context ~context-src
     (timbre/log! :fatal  :p ~args ~{:?line (@#'timbre/fline &form)})))

(defmacro report
  [context-src & args]
  `(with-a-frame-log-context ~context-src
     (timbre/log! :report :p ~args ~{:?line (@#'timbre/fline &form)})))

;;; Log using format-style args
(defmacro logf*
  [context-src config level & args]
  `(with-a-frame-log-context ~context-src
     (timbre/log! ~level  :f ~args ~{:?line (@#'timbre/fline &form) :config config})))

(defmacro logf
  [context-src level & args]
  `(with-a-frame-log-context ~context-src
     (timbre/log! ~level  :f ~args ~{:?line (@#'timbre/fline &form)})))

(defmacro tracef
  [context-src & args]
  `(with-a-frame-log-context ~context-src
     (timbre/log! :trace  :f ~args ~{:?line (@#'timbre/fline &form)})))

(defmacro debugf
  [context-src & args]
  `(with-a-frame-log-context ~context-src
     (timbre/log! :debug  :f ~args ~{:?line (@#'timbre/fline &form)})))

(defmacro infof
  [context-src & args]
  `(with-a-frame-log-context ~context-src
     (timbre/log! :info   :f ~args ~{:?line (@#'timbre/fline &form)})))

(defmacro warnf
  [context-src & args]
  `(with-a-frame-log-context ~context-src
     (timbre/log! :warn   :f ~args ~{:?line (@#'timbre/fline &form)})))

(defmacro errorf
  [context-src & args]
  `(with-a-frame-log-context ~context-src
     (timbre/log! :error  :f ~args ~{:?line (@#'timbre/fline &form)})))

(defmacro fatalf
  [context-src & args]
  `(with-a-frame-log-context ~context-src
     (timbre/log! :fatal  :f ~args ~{:?line (@#'timbre/fline &form)})))

(defmacro reportf
  [context-src & args]
  `(with-a-frame-log-context ~context-src
     (timbre/log! :report :f ~args ~{:?line (@#'timbre/fline &form)})))
aliostad/deep-learning-lang-detection
(ns server.projects-test
  (:require [server.projects :as sut]
            [midje.sweet :refer :all]
            [hydrox.core :as hydrox]
            [taoensso.timbre :refer [log spy] :as timbre]
            [clojure.test :refer [deftest is] :as t]
            [clojure.test.check :as tc]
            [clojure.spec :as s]
            [clojure.spec.gen :as gen]
            [clojure.spec.test :as stest]
            [server.db :as db]))

(background (timbre/-log! anything anything anything anything anything anything anything anything anything anything) => nil)
aliostad/deep-learning-lang-detection
(ns server.namespaces-test
  (:require [server.namespaces :as sut]
            [midje.sweet :refer :all]
            [hydrox.core :as hydrox]
            [taoensso.timbre :refer [log spy] :as timbre]
            [clojure.test :refer [deftest is] :as t]
            [clojure.test.check :as tc]
            [clojure.spec :as s]
            [clojure.spec.gen :as gen]
            [clojure.spec.test :as stest]
            [server.db :as db]))

(background (timbre/-log! anything anything anything anything anything anything anything anything anything anything) => nil)
zalando-incubator/chisel
(ns chisel.access-logs-test
  (:require [clojure.test :refer :all]
            [clj-http.client :as http]
            [taoensso.timbre :as timbre]
            [chisel.access-logs :as access-logs]
            [chisel.test-utils :as test-utils]
            [io.pedestal.log :as pedestal-log]))

  (testing "When timbre is used as backend, it gets called on http request"
    (let [log-args (atom nil)]
      (with-redefs [timbre/-log! (fn [& args] (reset! log-args args))]
        (test-utils/with-running-server {:port        port
                                         :interceptor access-logs/interceptor}
          (http/get location)
          (is (not (nil? @log-args)))))))