Fork me on GitHub
#beginners
<
2023-04-03
>
Aviv Kotek11:04:52

hey, i'm using standard clojure logging when populating logs to file with logstash, it does not remove Keywords,

;; logging
                 [ch.qos.logback/logback-classic "1.2.11"]
                 [net.logstash.logback/logstash-logback-encoder "7.2"]
                 [org.clojure/tools.logging "1.2.4"]
                 [ring-logger "1.1.1"]
=>
{"@timestamp":"2023-04-03T13:54:04.939+03:00", 
"message":"{:price 253.17, :api XXXX, :appCompletePercentage 0, :appStatus 100}}
is there a way to remove keywords without touching any code /etc? some library or Clojure encoder the desired outcome would be json-string without keywords,

Ben Sless12:04:27

you mean you want structured json logging?

theequalizer7323:04:31

hey friends, I’m trying to request an image from azure blob, with this code

(defn get-blob
  [sas-token storage-account container blob-name]
  (let [request-url (str "https://" storage-account "." container "/" blob-name sas-token)
        resp (http/get request-url)]
    (when (= (:status resp) 200)
      (let [image-str (:body resp)]
        (prn "image-str type: " (type image-str))
        image-str))))
I’m getting a string as body "image-str type: " java.lang.String and the response is something like this:
"����JFIF����C\t\b\b\t\r\r\r\r\f\f\f\f��C
 
 \f��\b��\"���\b\t
 }!1AQa\"q2���\b#B��R��$3br�\t
 %&'()*456789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz�������������������������������������������������������������������������\b\t
 w!1AQaq\"2�\bB����\t#3R�br�..."
how can I take this string and save it as an image file? I know what’s the type of image from the blob-name

phronmophobic23:04:07

Since image data is not character data, you'll want to get the response as something other than a string. Here's an example using an input stream:

(require '[ :as io])
(let [resp (http/get request-url
                     {:as :stream})]
  (with-open [input-stream (:body resp)
              output-stream (io/output-stream "my-image.png")]
    (io/copy input-stream output-stream)))

phronmophobic23:04:32

(assuming you're using clj-http)

theequalizer7323:04:14

Yes, I’m using clj-http. Let me try your snippet

theequalizer7323:04:14

It works! 🎉 Thank you!!

🎉 1
clojure-spin 1