This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-06-17
Channels
- # announcements (2)
- # aws (4)
- # babashka (20)
- # beginners (256)
- # calva (15)
- # chlorine-clover (1)
- # cider (12)
- # clj-kondo (25)
- # cljsrn (16)
- # clojure (115)
- # clojure-europe (7)
- # clojure-finland (5)
- # clojure-italy (10)
- # clojure-nl (35)
- # clojure-spec (13)
- # clojure-uk (83)
- # clojurescript (42)
- # code-reviews (81)
- # conjure (8)
- # cursive (6)
- # data-science (1)
- # datomic (3)
- # duct (18)
- # emacs (2)
- # figwheel-main (40)
- # fulcro (21)
- # helix (1)
- # jackdaw (7)
- # java (2)
- # lein-figwheel (5)
- # luminus (1)
- # observability (12)
- # off-topic (32)
- # parinfer (5)
- # pedestal (19)
- # re-frame (5)
- # reagent (8)
- # reitit (17)
- # rewrite-clj (47)
- # rum (19)
- # shadow-cljs (48)
- # spacemacs (4)
- # sql (40)
- # tools-deps (22)
- # vrac (1)
- # xtdb (25)
Thanks everyone for your comments! I remember we were using MDC years ago when I work solely with Java.
This discussion encouraged me to add a with-log-context
macro to our code base today. It takes a context (usually) a hash map, and a body to be executed and stringizes the context (into a CloseableThreadContext
). Very useful! Thank you all again for the nudge!
Here's what I added
(defn- stringize-context
"Given a logging context (that is hopefully a hash map), return a
hash map with strings for keys and for values. If the context is
not a hash map, return a hash map with a ctx string key and the
context value as a string."
[ctx]
(if (map? ctx)
(reduce-kv (fn [m k v]
(assoc m
(if (keyword? k) (name k) (str k))
(pr-str v)))
{}
ctx)
{"ctx" (pr-str ctx)}))
(defmacro with-log-context
"Given a hash map and a body, add the hash map to the log4j2 mapped
diagnostic context, and execute the body."
[ctx & body]
`(with-open [_# (CloseableThreadContext/putAll (stringize-context ~ctx))]
~@body))
Assuming :import
of (org.apache.logging.log4j CloseableThreadContext)
Any recommendations on parsing log file data? Looking to write a little utility to stream in logs from a kubernetes cluster and performe Clojuresque voodoo upon the data.
I think the best answer is to use logging that's meant to be machine readable, my company has had good luck with cambium json logging https://cambium-clojure.github.io/
oh - the logs aren't from clojure originally...
Right. In fact, they're from a variety of sources in a variety of formats, now that I look at them, so I don't know if I'll find something out of the box to cover the spectrum. But maybe something as an example to get started would be helpful.
I guess in theory the spectrum goes from regex to instaparse(?) -- google shows me a few libs but I can't tell you if any are better than others
Thanks, this might do it, especially in conjunction with https://github.com/lambdaisland/regal.