 
   ## Helpers
 
-  defp log_event({:error, _gl, {pid, format, data}}, %{otp: true}),
-    do: log_event(:error, :format, pid, {format, data})
-  defp log_event({:error_report, _gl, {pid, :std_error, format}}, %{otp: true}),
-    do: log_event(:error, :report, pid, {:std_error, format})
+  defp log_event({:error, _gl, {pid, format, data}}, %{otp: true} = state),
+    do: log_event(:error, :format, pid, {format, data}, state)
+  defp log_event({:error_report, _gl, {pid, :std_error, format}}, %{otp: true} = state),
+    do: log_event(:error, :report, pid, {:std_error, format}, state)
 
-  defp log_event({:warning_msg, _gl, {pid, format, data}}, %{otp: true}),
-    do: log_event(:warn, :format, pid, {format, data})
-  defp log_event({:warning_report, _gl, {pid, :std_warning, format}}, %{otp: true}),
-    do: log_event(:warn, :report, pid, {:std_warning, format})
+  defp log_event({:warning_msg, _gl, {pid, format, data}}, %{otp: true} = state),
+    do: log_event(:warn, :format, pid, {format, data}, state)
+  defp log_event({:warning_report, _gl, {pid, :std_warning, format}}, %{otp: true} = state),
+    do: log_event(:warn, :report, pid, {:std_warning, format}, state)
 
-  defp log_event({:info_msg, _gl, {pid, format, data}}, %{otp: true}),
-    do: log_event(:info, :format, pid, {format, data})
-  defp log_event({:info_report, _gl, {pid, :std_info, format}}, %{otp: true}),
-    do: log_event(:info, :report, pid, {:std_info, format})
+  defp log_event({:info_msg, _gl, {pid, format, data}}, %{otp: true} = state),
+    do: log_event(:info, :format, pid, {format, data}, state)
+  defp log_event({:info_report, _gl, {pid, :std_info, format}}, %{otp: true} = state),
+    do: log_event(:info, :report, pid, {:std_info, format}, state)
 
   defp log_event(_, _state),
     do: :ok
 
-  defp log_event(level, kind, pid, data) do
+  defp log_event(level, kind, pid, data, state) do
     %{level: min_level, truncate: truncate,
       utc_log: utc_log?, translators: translators} = Logger.Config.__data__
 

  require Logger

  def init({otp?, threshold}) do
    {:ok, %{otp: otp?, threshold: threshold,
            last_length: 0, last_time: :os.timestamp, dropped: 0}}
  end


      message = Logger.Utils.truncate(message, truncate)

      # Mode is always async to avoid clogging the error_logger
      GenEvent.notify(state.logger,
        {level, Process.group_leader(),
          {Logger, message, Logger.Utils.timestamp(utc_log?), [pid: ensure_pid(pid)]}})
    end
