Beginner's problem: Using Logger

I’m working on my first Elixir project. I’m doing the Github issues project following the instruction in Dave Thomas’s Programming Elixir book.

I have this in my github_issues.ex file:

defmodule Issues.GithubIssues do
  require Logger

  @user_agent [{"User-agent",
                "crisefd"}]

  @github_url Application.get_env(:issues, :github_url)

  def fetch(user, project) do
    Logguer.info("Fetching #{user}'s project #{project}'")
    issues_url(user, project)
    |> HTTPoison.get(@user_agent)
    |> handle_response
  end

  defp issues_url(user, project) do
    "#{@github_url}/repos/#{user}/#{project}/issues"
  end

  defp  handle_response({_, %{status_code: status_code, body: body}})  do
    Logger.info("Got response: status code=#{status_code}")
    Logger.debug(fn -> inspect(body) end)
    {
      status_code |> check_for_errors(),
      body |> Poison.Parser.parse!()
    }
  end

  defp check_for_errors(200), do: :ok
  defp check_for_errors(_), do: :error

end

But I’m getting this error when running the app with iex -S mix:

iex(1)>  Issues.CLI.process {"myuser", "myproject", 4}
** (UndefinedFunctionError) function Logguer.info/1 is undefined (module Logguer is not available)
    Logguer.info("Fetching crisefd's project angular'")
    (issues) lib/issues/github_issues.ex:10: Issues.GithubIssues.fetch/2
    (issues) lib/issues/cli.ex:38: Issues.CLI.process/1

This is my config.ex:

use Mix.Config
config :issues, github_url: "https://api.github.com"
config :logger, compile_time_purge_level: :debug

You have misspelled Logger. There is an errand U in it

2 Likes

(facepalm) I knew it had to be something dumb. Thanks a lot.

1 Like

No worries, we all tend to miss the obvious when focusing too hard on a subjectively harder problem :wink:

A tip I think is useful for every new programming language you try: Read the error messages very carefully, even if it seems like gibberish and google keywords you don’t understand.

I’ve had a hard time getting used to elixir error message in the beginning (they have improved a ton since I started using elixir), but when I finally warmed up to elixirs errors, I felt like I could debug everything! (I can’t, but it’s nice to have that false confidence when diving into a new project)

In this particular case, the error was very blatant “module Logguer is not available”, but every blunder is an opportunity to learn!

1 Like