viesti / timbre-json-appender

JSON appender for Timbre
MIT License
44 stars 11 forks source link

Add :level-key to specify a different option for the level/severity which is required for GCP #11

Closed xlfe closed 3 years ago

xlfe commented 3 years ago

GCP Logging seems to require level to be under the "severity" key in the json payload

https://stackoverflow.com/questions/43208878/how-does-stackdriver-logging-assert-the-severity-of-an-entry

viesti commented 3 years ago

Ah, this is a nice catch for GCP. Thank you! :)

viesti commented 3 years ago

Pushed as 0.1.3 to Clojars, thanks for the readme & changelog entry too :)

xlfe commented 3 years ago

No worries. I'm sorry I should have tested it in GCP first as in dev I get the following :-

{"timestamp":"2020-11-07T11:50:29Z","severity":"info","thread":"main","msg":"HTTP server started"}

but when I look at my logs out of a GCP instance the severity has been set to default (and removed from the entry)

{
  "insertId": "<INSERT_ID>",
  "jsonPayload": {
    "timestamp": "2020-11-07T11:55:06Z",
    "msg": "HTTP server started",
    "thread": "main"
  },
  "resource": {
    "type": "k8s_container",
    "labels": {
      "location": "location",
      "namespace_name": "default",
      "project_id": "project",
      "container_name": "app",
      "pod_name": "cluster-1234-5678",
      "cluster_name": "cluster"
    }
  },
  "timestamp": "2020-11-07T11:55:06.919787738Z",
  "labels": {
    "compute.googleapis.com/resource_name": "gke-pool",
    "k8s-pod/pod-template-hash": "hash",
    "k8s-pod/app": "app"
  },
  "logName": "projects/<PROJECT>/logs/<PROJECT>"
  "receiveTimestamp": "2020-11-07T11:55:08.101134459Z"
}

It looks like GCP is expecting the level to be all uppercase :/

https://cloud.google.com/logging/docs/reference/v2/rest/v2/LogEntry#LogSeverity

I'll get you another PR addressing that problem tomorrow lol

xlfe commented 3 years ago

All good. I just needed the following timbre middleware :+1:

(def gcp-maps {:trace  :DEBUG                                                                                      
               :debug  :DEBUG                                                                            
               :info   :INFO                                                                             
               :warn   :WARNING                                                                          
               :error  :ERROR                                                                            
               :fatal  :CRITICAL                                                                         
               :report :DEFAULT})                                                                        

(defn gcp-levels                                                                                           
  [data]                                                                                                   
  (update data :level gcp-maps))                                                                                                          
viesti commented 3 years ago

All good :) Middleware sounds like a good fit for this situation.