         with :ok <- UART.write(uart_pid(), @off),
              :ok <- UART.drain(uart_pid()),
              :ok <- UART.close(uart_pid()),
-             do: remove_backend(Map.get(state, port))
+             do: remove_backend(Map.get(state, port).log_path)
 
       case msg do
         :ok ->

  defp remove_backend(path) do
    Logger.remove_backend({LoggerFileBackend, path})
  end
end

  def handle_call({:start_logging, opts}, _from, state) do
    port = Keyword.get(opts, :port, default_port())
    log_path = Keyword.get(opts, :log_path, @default_log_path) |> Path.expand()
    sample_rate = Keyword.get(opts, :sample_rate, @default_sample_rate)

    if Map.has_key?(state, port) do
      {:reply, {:error, :eagain}, state}
