Nebo15 / logger_json

JSON logger formatter with support for Google Cloud, DataDog and other for Elixir.

Home Page:https://nebo15.github.io/logger_json/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How do we customise metadata sent to GCL?

christopherdbull opened this issue · comments

Hey, first, thanks for making this, it's exactly what I need! I want to send our session id and userid along with our log entries for grouping/analysis later. Is there a way to pass this in when I use the plug?

Hey @TE-Chris. There are multiple ways to do that, probably the best one is to define your own Plug metadata formatter and extend it the way you need (here is the default one - https://github.com/Nebo15/logger_json/blob/master/lib/logger_json/plug/metadata_formatters/google_cloud_logger.ex).

Alternatively, if you don't need it in the same log entry as default request log coming from plug, you can simply create a small plug that logs that using Logger.log("Message", user_id: ..., session_id: ...).

Was afraid you'd say that hah :) Sounds good, will look into doing it that way. Thanks!