Glen
Glen

Reputation: 801

Elixir Logger - How do You Modify the Contents of a Logged Message?

Is there any way to hook into the Elixir Logger before messages get sent to the backends? I need to strip out potentially sensitive information before it gets written to external systems.

Upvotes: 3

Views: 898

Answers (1)

Onorio Catenacci
Onorio Catenacci

Reputation: 15343

Just for the sake of others who might come across this question and not notice the comment I posted, I believe you can accomplish what you're trying to achieve via the Logger.Translator module. You would build a module and function to pattern match on the sensitive data that you want to filter and then add the module and function via the Logger.add_translator/1 function.


EDIT: In response to the comment left by the poster of the original question: I suggest you look here and look specifically at these two options: :handle_otp_reports and :handle_sasl_reports. I'd also draw your attention to this passage in the documentation:

Furthermore, Logger allows messages sent by Erlang’s error_logger to be translated into an Elixir format via translators.

Assuming you're outputting the messages that you want to filter via Erlang's error_logger, this is the right approach. If you're not outputting those messages via error_logger then please add more detail about the mechanism you're using to output the messages you want to scrub.

Upvotes: 3

Related Questions