diff --git a/src/micro_blog/config.clj b/src/micro_blog/config.clj index b049413..feaa106 100644 --- a/src/micro_blog/config.clj +++ b/src/micro_blog/config.clj @@ -11,7 +11,6 @@ :mastodon-account-id "MASTODON_ACCOUNT_ID"}) (defn- load-config [] - (tel/log! :info "Config is being loaded") (merge (read-string (slurp "config.edn")) (into {} (for [[k env-var] env-overrides :let [env-val (System/getenv env-var)] diff --git a/src/micro_blog/logging.clj b/src/micro_blog/logging.clj new file mode 100644 index 0000000..462a260 --- /dev/null +++ b/src/micro_blog/logging.clj @@ -0,0 +1,31 @@ +(ns micro-blog.logging + (:import [java.time Instant]) + (:require + [taoensso.telemere :as tel] + [cheshire.core :as json] + [cheshire.generate :as gen])) + +(def json-logging-handler + (tel/handler:console + {:output-fn + (tel/pr-signal-fn + {:clean-fn (fn [signal] + (-> signal + (assoc :message (get signal :msg_)) + (dissoc :kind :msg_ :schema + :run-val + :kvs :end-inst :run-form :sample :_otel-context + :root :thread :run-nsecs :parent))) + :pr-fn json/generate-string})})) + +(gen/add-encoder Instant + (fn [c jsonGenerator] + (.writeString jsonGenerator (.toString c)))) + +(defn setup-logging [] + (tel/remove-handler! :default/console) + (tel/add-handler! ::json-logger json-logging-handler)) + +(defn test-logging [] + (setup-logging) + (tel/log! {:level :info :data {:thing "example"}} "This is a test log message")) diff --git a/src/micro_blog/main.clj b/src/micro_blog/main.clj index 098c302..dc79cec 100644 --- a/src/micro_blog/main.clj +++ b/src/micro_blog/main.clj @@ -3,6 +3,7 @@ (:import [java.time Instant Duration]) (:require [chime.core :as chime] [taoensso.telemere :as tel] + [micro-blog.logging] [micro-blog.blue-sky :as blue-sky] [micro-blog.mastodon :as masto])) @@ -10,10 +11,12 @@ masto/run]) (defn -main [] + (micro-blog.logging/setup-logging) (tel/log! :info "Setting up crons") (doseq [[i cron] (map-indexed vector crons)] (let [start (.plus (Instant/now) (Duration/ofMinutes (* i 5)))] (chime/chime-at (chime/periodic-seq start (Duration/ofMinutes 30)) (fn [_time] (cron))))) - @(promise)) + @(promise) + (tel/stop-handlers!))