From f3845d5e599f8d8d04eb291402d20163ba3d8097 Mon Sep 17 00:00:00 2001 From: tylerwitt-pcln Date: Wed, 21 Jun 2023 16:55:10 +0200 Subject: [PATCH] Update Logger implementation to be purgeable Using Logger.log makes compile time purge matching not possible, which means logging is all or nothing with regards to purging. This change would allow compile time purge matching by log level, so one could get rid of debug logging instead of all logging. --- lib/new_relic/logger.ex | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/new_relic/logger.ex b/lib/new_relic/logger.ex index 0ea041e0..cc02d6a6 100644 --- a/lib/new_relic/logger.ex +++ b/lib/new_relic/logger.ex @@ -31,7 +31,7 @@ defmodule NewRelic.Logger do # Server def handle_cast({:log, level, message}, %{io_device: Logger} = state) do - Logger.log(level, "new_relic_agent - " <> message) + elixir_logger(level, "new_relic_agent - " <> message) {:noreply, state} end @@ -79,6 +79,11 @@ defmodule NewRelic.Logger do {:ok, _file} = File.open(logfile, [:append, :utf8]) end + defp elixir_logger(:debug, message), do: Logger.debug(message) + defp elixir_logger(:info, message), do: Logger.info(message) + defp elixir_logger(:warn, message), do: Logger.warn(message) + defp elixir_logger(:error, message), do: Logger.error(message) + @sep " - " def formatted(level, message), do: [formatted(level), @sep, timestamp(), @sep, message, "\n"] def formatted(:debug), do: "[DEBUG]"