From c0945cddb5329308bd167921b2573d05c5f72e59 Mon Sep 17 00:00:00 2001 From: Arne Brasseur Date: Sun, 4 Dec 2022 10:39:46 +0100 Subject: [PATCH] logging setup and user.clj --- deps.edn | 9 +++- dev/user.clj | 49 ++++++++++++++++++- repl_sessions/poke_classpath.clj | 4 ++ repl_sessions/poke_logging.clj | 4 ++ resources/lambdaisland/souk/settings.edn | 2 +- resources/logback.xml | 12 +++++ src/lambdaisland/souk/components/router.clj | 2 +- .../souk/{ => util}/dev_router.clj | 2 +- 8 files changed, 79 insertions(+), 5 deletions(-) create mode 100644 repl_sessions/poke_classpath.clj create mode 100644 repl_sessions/poke_logging.clj create mode 100644 resources/logback.xml rename src/lambdaisland/souk/{ => util}/dev_router.clj (96%) diff --git a/deps.edn b/deps.edn index c603c31..fb3ad6a 100644 --- a/deps.edn +++ b/deps.edn @@ -3,7 +3,7 @@ ;; Application setup com.lambdaisland/webbing {:local/root "/home/arne/github/lambdaisland/webbing"} -;; {:mvn/version "0.4.20-alpha"} + ;; {:mvn/version "0.4.20-alpha"} ;; Incoming HTTP ring/ring-core {:mvn/version "1.9.6"} ring/ring-jetty-adapter {:mvn/version "1.9.6"} @@ -21,6 +21,13 @@ ;; Database seancorfield/next.jdbc {:mvn/version "1.2.659"} com.impossibl.pgjdbc-ng/pgjdbc-ng {:mvn/version "0.8.9"} + + ;; Logging + ;; Webbing pulls in pedestal-log/glogi, but does not dictate the logging sink + org.slf4j/jul-to-slf4j {:mvn/version "2.0.3"} + org.slf4j/jcl-over-slf4j {:mvn/version "2.0.3"} + org.slf4j/log4j-over-slf4j {:exclusions [org.slf4j/slf4j-nop], :mvn/version "2.0.3"} + ch.qos.logback/logback-classic {:exclusions [org.slf4j/slf4j-api org.slf4j/slf4j-nop] :mvn/version "1.4.4"} } :aliases diff --git a/dev/user.clj b/dev/user.clj index cae03eb..7bdc540 100644 --- a/dev/user.clj +++ b/dev/user.clj @@ -1,3 +1,50 @@ (ns user) -(set! *print-namespace-maps* false) +(alter-var-root #'*print-namespace-maps* (constantly false)) + +(defmacro jit [sym] + `(requiring-resolve '~sym)) + +(def sys-id :lambdaisland/souk-dev) + +(defn go [] + ((jit lambdaisland.webbing.dev/register!) sys-id 'lambdaisland.souk.setup/dev-setup) + ((jit lambdaisland.webbing.dev/start!) {:sys-id sys-id})) + +(defn stop! [] + ((jit lambdaisland.webbing.dev/stop!) {:sys-id sys-id})) + +(defn restart [] + ((jit lambdaisland.webbing.dev/restart) sys-id)) + +(defn reset [] + (stop!) + ((jit clojure.tools.namespace.repl/set-refresh-dirs) "src" "test") + ((jit clojure.tools.namespace.repl/refresh) :after `restart)) + +(defn reset-all [] + (stop!) + ((jit clojure.tools.namespace.repl/set-refresh-dirs) "src" "test") + ((jit clojure.tools.namespace.repl/refresh-all) :after `restart)) + +(def portal-instance (atom nil)) + +(defn portal + "Open a Portal window and register a tap handler for it. The result can be + treated like an atom." + [] + (let [p ((jit portal.api/open) @portal-instance)] + (reset! portal-instance p) + (add-tap (jit portal.api/submit)) + p)) + +(defn value [k] + (get ((jit k16.gx.beta.system/values) sys-id) k)) + +(defn browse [] + ((jit clojure.java.browse/browse-url) "http://localhost:9400/live")) + +(comment + + (value :http/server) +) diff --git a/repl_sessions/poke_classpath.clj b/repl_sessions/poke_classpath.clj new file mode 100644 index 0000000..dffcd76 --- /dev/null +++ b/repl_sessions/poke_classpath.clj @@ -0,0 +1,4 @@ +(ns repl-sessions.poke-classpath + (:require [lambdaisland.classpath :as licp])) + +(licp/classpath-chain) diff --git a/repl_sessions/poke_logging.clj b/repl_sessions/poke_logging.clj new file mode 100644 index 0000000..fc8967b --- /dev/null +++ b/repl_sessions/poke_logging.clj @@ -0,0 +1,4 @@ +(ns repl-sessions.poke-logging + (:require [lambdaisland.glogc :as log])) + +(log/warn :hello "world") diff --git a/resources/lambdaisland/souk/settings.edn b/resources/lambdaisland/souk/settings.edn index 6a7e3a5..d397190 100644 --- a/resources/lambdaisland/souk/settings.edn +++ b/resources/lambdaisland/souk/settings.edn @@ -1,2 +1,2 @@ -{:port 3444 +{:port 3838 :dev/reload-routes? false} diff --git a/resources/logback.xml b/resources/logback.xml new file mode 100644 index 0000000..0a99fec --- /dev/null +++ b/resources/logback.xml @@ -0,0 +1,12 @@ + + + + [%d{HH:mm:ss.SSS}] %highlight([%level]) [%logger] %msg%n + + + + + + + + diff --git a/src/lambdaisland/souk/components/router.clj b/src/lambdaisland/souk/components/router.clj index 081a405..5b86ad5 100644 --- a/src/lambdaisland/souk/components/router.clj +++ b/src/lambdaisland/souk/components/router.clj @@ -1,7 +1,7 @@ (ns lambdaisland.souk.components.router "Reitit routes and router" (:require - [lambdaisland.souk.dev-router :as dev-router] + [lambdaisland.souk.util.dev-router :as dev-router] [muuntaja.core :as muuntaja] [reitit.dev.pretty :as pretty] [reitit.ring :as reitit-ring] diff --git a/src/lambdaisland/souk/dev_router.clj b/src/lambdaisland/souk/util/dev_router.clj similarity index 96% rename from src/lambdaisland/souk/dev_router.clj rename to src/lambdaisland/souk/util/dev_router.clj index 71fc8b8..c5c6ee3 100644 --- a/src/lambdaisland/souk/dev_router.clj +++ b/src/lambdaisland/souk/util/dev_router.clj @@ -1,4 +1,4 @@ -(ns lambdaisland.souk.dev-router +(ns lambdaisland.souk.util.dev-router "Reitit router wrapper that auto-rebuilds, for REPL workflows." (:require [reitit.core :as reitit]))