Skip to content

Instantly share code, notes, and snippets.

@xlfe
Last active November 4, 2024 21:36
Show Gist options
  • Save xlfe/e9e2cf23bd1dddcbb2fbd77ce31dcc8b to your computer and use it in GitHub Desktop.
Save xlfe/e9e2cf23bd1dddcbb2fbd77ce31dcc8b to your computer and use it in GitHub Desktop.
How to get Structured Logging on GCP with Telemere
(def gcp-json-handler
(tele/handler:console
{:output-fn (tele/pr-signal-fn
{:pr-fn jsonista.core/write-value-as-string
:clean-fn (tele/clean-signal-fn {:incl-kvs? true})})}))
(def encore-levels->gcp-severity
{:trace :DEFAULT ; (0) The log entry has no assigned severity level.
:debug :DEBUG ; (100) Debug or trace information.
:info :INFO ; (200) Routine information, such as ongoing status or performance.
:warn :WARNING ; (400) Warning events might cause problems.
:error :ERROR ; (500) Error events are likely to cause problems.
:fatal :CRITICAL ; (600) Critical events cause more severe problems or outages.
:report :ALERT}) ; (700) A person must take an action immediately.
(tele/add-handler!
:default/console
gcp-json-handler
{:ns-filter {:disallow "org.eclipse.jetty.server.*"}
:middleware (fn [{:as signal
:keys [level]}]
(assoc signal :severity (get encore-levels->gcp-severity level)))})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment