make logging loki compatable
This commit is contained in:
parent
8263c09b50
commit
edc74be72b
3 changed files with 35 additions and 2 deletions
|
|
@ -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)]
|
||||
|
|
|
|||
31
src/micro_blog/logging.clj
Normal file
31
src/micro_blog/logging.clj
Normal file
|
|
@ -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"))
|
||||
|
|
@ -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!))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue