Created
February 16, 2022 14:44
-
-
Save ichramm/6e8404cd234debd38271288b0e17a989 to your computer and use it in GitHub Desktop.
clojure log wrappers
This file contains hidden or 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 ichramm.log | |
(:require [clojure.tools.logging :as log])) | |
(def ^:macro trace #'log/trace) | |
(def ^:macro debug #'log/debug) | |
(def ^:macro info #'log/info) | |
(def ^:macro warn #'log/warn) | |
(def ^:macro error #'log/error) | |
(def ^:macro fatal #'log/fatal) | |
(def ^:macro tracef #'log/tracef) | |
(def ^:macro debugf #'log/debugf) | |
(def ^:macro infof #'log/infof) | |
(def ^:macro warnf #'log/warnf) | |
(def ^:macro errorf #'log/errorf) | |
(def ^:macro fatalf #'log/fatalf) | |
(defmacro thread-left | |
[level x & more] | |
(if-not (seq more) | |
`(do | |
(~level ~x) | |
~x) | |
(if (ifn? (first more)) | |
`(do | |
(~level ~@(rest more) (~(first more) ~x)) | |
~x) | |
`(do | |
(~level ~@more ~x) | |
~x)))) | |
(defmacro thread-right | |
[level x & more] | |
(if-not (seq more) | |
`(do | |
(~level ~x) | |
~x) | |
(if (ifn? x) | |
`(do | |
(~level ~@(butlast more) (~x ~(last more))) | |
~(last more)) | |
`(do | |
(~level ~x ~@more) | |
~(last more))))) | |
(defmacro trace-> [& args] `(thread-left trace ~@args)) | |
(defmacro debug-> [& args] `(thread-left debug ~@args)) | |
(defmacro info-> [& args] `(thread-left info ~@args)) | |
(defmacro warn-> [& args] `(thread-left warn ~@args)) | |
(defmacro error-> [& args] `(thread-left error ~@args)) | |
(defmacro fatal-> [& args] `(thread-left fatal ~@args)) | |
(defmacro trace->> [& more] `(thread-right trace ~@more)) | |
(defmacro debug->> [& args] `(thread-right debug ~@args)) | |
(defmacro info->> [& args] `(thread-right info ~@args)) | |
(defmacro warn->> [& args] `(thread-right warn ~@args)) | |
(defmacro error->> [& args] `(thread-right error ~@args)) | |
(defmacro fatal->> [& args] `(thread-right fatal ~@args)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment