From 62878a9ac3f5eec5cff1fb651e536004cbffacaa Mon Sep 17 00:00:00 2001 From: Louise Klodt <155456263+louiseklodt-kroo@users.noreply.github.com> Date: Fri, 16 Feb 2024 17:42:14 +0000 Subject: [PATCH] Make the logging macros produced by `deflevel` multi-arity (#1) * make deflevel macro multi-arity --- README.md | 3 +++ build/README.md | 2 +- examples/logback/README.md | 2 +- examples/logback/src/com/example/logging/core.clj | 5 +++++ src/com/kroo/epilogue.clj | 7 +++++-- 5 files changed, 15 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 89dc255..57fcc13 100644 --- a/README.md +++ b/README.md @@ -79,6 +79,9 @@ The core of any logging tool is being able to make logs: ;; Programatically log at different levels with `log`. (log/log :warn "Warning about something" {:what? "something..."}) + +;; Just log a message without data or options. +(log/info "This is just a log message") ``` diff --git a/build/README.md b/build/README.md index 506dc91..2bc1acc 100644 --- a/build/README.md +++ b/build/README.md @@ -26,7 +26,7 @@ If there was no Git tag pointing to the commit, the jar will have the version: ` ## Deploy -Create a Git tag for the version to build (preferrably prefixed with `v`) pointing at the relevant commit. +Create a Git tag for the version to build (preferably prefixed with `v`) pointing at the relevant commit. Run this command (replacing the username and password with your own and the version with the Git tag), which will test, build and deploy the jar to Clojars. diff --git a/examples/logback/README.md b/examples/logback/README.md index ae5f262..247d6a2 100644 --- a/examples/logback/README.md +++ b/examples/logback/README.md @@ -4,4 +4,4 @@ This is an example Clojure project demonstrating how to use Epilogue (logging fr [Logback]: https://logback.qos.ch -It is using [Typeset.logback](https://github.com/b-social/typeset.logback) as the log formatter for Logback as it supports all of Epilogue's features and has excellent Clojure support. +It is using [Typeset.logback](https://github.com/b-social/typeset.logback) as the log formatter for Logback as it supports all of Epilogue's features and has excellent Clojure support. \ No newline at end of file diff --git a/examples/logback/src/com/example/logging/core.clj b/examples/logback/src/com/example/logging/core.clj index ff768e5..7aab799 100644 --- a/examples/logback/src/com/example/logging/core.clj +++ b/examples/logback/src/com/example/logging/core.clj @@ -7,3 +7,8 @@ (SLF4JBridgeHandler/install) (log/info "Log!" {:foo "bar"}) + +(defn run [& args] + (log/info "Log!" {:foo "bar"}) + (log/info "Log no data!")) + diff --git a/src/com/kroo/epilogue.clj b/src/com/kroo/epilogue.clj index 92329fe..8aefa5b 100644 --- a/src/com/kroo/epilogue.clj +++ b/src/com/kroo/epilogue.clj @@ -128,6 +128,7 @@ forms)] (when (seq idxs) idxs))) +; TODO change name to add-file-and-namespace ? (defn- preserve-form-meta [body] `(with-meta ~body (assoc (meta ~'&form) :file (str *file*), :namespace (str *ns*)))) @@ -170,8 +171,10 @@ " - a sequence of SLF4J `markers` (or strings/keywords), and\n" " - an override logger namespace (`logger-ns`).") :arglists '~'([msg data & {:keys [cause markers logger-ns]}])} - [msg# data# & opts#] - `(log ~~(keyword level) ~msg# ~data# ~@opts#))) + ([msg#] + `(log ~~(keyword level) ~msg# {})) + ([msg# data# & opts#] + `(log ~~(keyword level) ~msg# ~data# ~@opts#)))) ;; Generate convenience macros for the supported logging levels. (declare error warn info debug trace)