Skip to content

Instantly share code, notes, and snippets.

@henryw374
Created March 17, 2021 16:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save henryw374/a54d5934e567f4bd20a6ca6b052794d6 to your computer and use it in GitHub Desktop.
Save henryw374/a54d5934e567f4bd20a6ca6b052794d6 to your computer and use it in GitHub Desktop.
(ns my.ns
(:require [com.widdindustries.log4j2.log-api :as log]
[com.widdindustries.log4j2.config :as config]
[com.widdindustries.InfluxDbProvider :as influx]
[com.widdindustries.influx-data :as influx-data]
[com.widdindustries.log4j2.log-impl :as log-impl])
(:import [org.apache.logging.log4j.message MapMessage]
[org.apache.logging.log4j Level]
[org.influxdb InfluxDB InfluxDBFactory InfluxDB$ConsistencyLevel]
[org.influxdb.dto Query]))
(require '[com.widdindustries.InfluxDbProvider :as influx] :reload-all)
(defn setup-config []
(let [builder (config/builder)
std-out-appender-name "Stdout"
influx-appender-name "influx"]
(-> builder
(.add (config/std-out-appender builder std-out-appender-name
"%date %level %logger %message%n%throwable"))
;(.add (influx/no-sql-appender builder influx-appender-name))
(.add (config/root-logger builder org.apache.logging.log4j.Level/INFO std-out-appender-name))
(.add (config/logger builder Level/DEBUG std-out-appender-name "my.ns"))
;(.writeXmlConfiguration System/out)
(config/start)
))
)
(comment
(config/remove-all-appenders)
(config/stop context)
(config/context->data context)
(config/get-loggers context)
(def influx-url "http://localhost:8086")
(def context (setup-config))
(def appender (influx/appender {:influx-url influx-url
:database-name "mydb"
:create-db? true} 0))
(config/add-appender-to-running-context appender context)
;log string
(log/info "hello")
;log a Message (data)
(log/info (MapMessage. {"foo" "bar"}))
(log/info (influx-data/influx-point
"foo_measurement"
{"day" "weds" "weather" "sunny"}
{"temp" 23.4 "sunlight" 5.6}
) )
(def influx (InfluxDBFactory/connect influx-url))
(.setDatabase influx "mydb")
(.query influx (Query. "select * from foo_measurement"))
; varargs formatted string
(log/info "hello {} there" :foo)
; builder - include throwable|marker|location
(-> (log/info-builder)
(log/with-location)
(log/with-throwable *e)
(log/log "foo"))
)
@henryw374
Copy link
Author

(defn create-map-message [^Map m]
(let [message (MapMessage.)]
(doseq [entry (seq m)]
(.put message (str (key entry)) (val entry)))))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment