Skip to content

Instantly share code, notes, and snippets.

@ryu1kn
Last active March 13, 2023 18:59
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ryu1kn/e4650297b46874db89bde41079b464d5 to your computer and use it in GitHub Desktop.
Save ryu1kn/e4650297b46874db89bde41079b464d5 to your computer and use it in GitHub Desktop.
Use clojure to fetch Dialogflow log from Stackdriver
; src/clojure__gcp/core.clj
(ns clojure--gcp.core
(:import (com.google.cloud.logging LoggingOptions Logging$EntryListOption Logging)))
; Advanced logs queries: https://cloud.google.com/logging/docs/view/advanced-queries
(defn make-filter [project-id]
(str "logName = \"projects/" project-id "/logs/dialogflow_agent\"
labels.type = \"dialogflow_response\"
timestamp >= \"2020-04-05T00:00:00+11:00\""))
(defn dump-log []
(let [options (LoggingOptions/getDefaultInstance)
logging (.getService options)
list-opt (Logging$EntryListOption/filter (make-filter (.getProjectId options)))
entries (.listLogEntries (cast Logging logging) (into-array [list-opt]))]
(doseq [entry (.iterateAll entries)] (println entry))))
(defn -main [& args]
(dump-log))
; project.clj
(defproject clojure--gcp "0.1.0-SNAPSHOT"
:description "FIXME: write description"
:url "http://example.com/FIXME"
:license {:name "EPL-2.0 OR GPL-2.0-or-later WITH Classpath-exception-2.0"
:url "https://www.eclipse.org/legal/epl-2.0/"}
:dependencies [[org.clojure/clojure "1.10.0"]
[com.google.cloud/google-cloud-logging "1.101.0"]
]
:repl-options {:init-ns clojure--gcp.core}
:main clojure--gcp.core)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment