     cond do
       len > state.sync_threshold and state.mode == :async ->
         :sync
+
       len < state.async_threshold and state.mode == :sync ->
         :async
+
       true ->
         state.mode
     end

  end

  def handle_call({:configure, options}, state) do
    Enum.each options, fn {key, value} ->
      Application.put_env(:logger, key, value)
    end
    {:ok, :ok, compute_state(state.mode)}
  end


  defp update_translators(%{translators: translators} = state, fun) do
    translators = fun.(translators)
    Application.put_env(:logger, :translators, translators)
    persist(%{state | translators: translators})
  end

  defp compute_state(mode) do
    level = Application.get_env(:logger, :level)
    utc_log = Application.get_env(:logger, :utc_log)
    truncate = Application.get_env(:logger, :truncate)
    translators = Application.get_env(:logger, :translators)

    sync_threshold = Application.get_env(:logger, :sync_threshold)
    async_threshold = trunc(sync_threshold * 0.75)

    state = %{
      level: level,
      mode: mode,
      truncate: truncate,
      utc_log: utc_log,
      sync_threshold: sync_threshold,
      async_threshold: async_threshold,
      translators: translators
    }

    case compute_mode(state) do
      ^mode ->
        persist(state)

      new_mode ->
        persist(%{state | mode: new_mode})
    end
