Last active
March 13, 2023 18:59
-
-
Save ryu1kn/e4650297b46874db89bde41079b464d5 to your computer and use it in GitHub Desktop.
Use clojure to fetch Dialogflow log from Stackdriver
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; 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)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; 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