Skip to content

Commit

Permalink
Include SCM revision in the logs
Browse files Browse the repository at this point in the history
  • Loading branch information
pepijn committed Mar 28, 2021
1 parent eac84e0 commit 00798fd
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
2 changes: 1 addition & 1 deletion project.clj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(defproject nl.epij/google-cloud-function-background-adapter "0.1.0-alpha1"
(defproject nl.epij/google-cloud-function-background-adapter "0.1.0-alpha2"
:description "A Clojure adapter for background functions on GCP's Cloud Function Java Runtime"
:url "https://github.com/pepijn/google-cloud-function-background-adapter"
:license {:name "MIT"
Expand Down
11 changes: 9 additions & 2 deletions src/clojure/nl/epij/gcp/gcf/log.clj
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
(ns nl.epij.gcp.gcf.log
(:require [clojure.walk :as walk]
[cheshire.core :as json]
[cheshire.generate :refer [add-encoder encode-str]])
[cheshire.generate :refer [add-encoder encode-str]]
[clojure.java.io :as io])
(:import [org.slf4j LoggerFactory Logger]
[net.logstash.logback.argument StructuredArguments]
[com.fasterxml.jackson.core JsonGenerationException]
Expand All @@ -10,14 +11,20 @@
(def ^Logger logger
(LoggerFactory/getLogger ^String (.toString *ns*)))

(def revision
(-> (io/resource "metadata.json")
(slurp)
(json/parse-string)
(get "revision")))

(add-encoder HttpRequestImpl encode-str)
(add-encoder HttpClientFacade encode-str)

(defn log
[level ^String message data]
(let [data' (-> (walk/stringify-keys data)
(assoc "severity" level)
(assoc "revision" "TODO"))
(assoc "revision" revision))
structured-arguments (mapcat (fn [[k v]]
(cond (nil? v)
[]
Expand Down

0 comments on commit 00798fd

Please sign in to comment.