richeyb / runnable-elixir

An example Elixir application that can be run via mix run, mix tasks, or via IEX
4 stars 4 forks source link

This project is not a template for the Ultimate Logging Tutorial #1

Open 7stud opened 5 years ago

7stud commented 5 years ago

I'm reading the logging tutorial here:

https://timber.io/blog/the-ultimate-guide-to-logging-in-elixir/

and this project is supposed to be a template for that tutorial. It is not!
There is no way that this project will call a private log/0 function when you execute:

$ mix run

Do you know why? Because there is no log/0 function anywhere. Where is the template that we are supposed to use? Better yet, why is there a template in the first place? The tutorial should start off with:

$ mix new myproj

7stud commented 5 years ago

For anyone who wants to follow along with the tutorial, you can use the following modifications:

greeting.ex:

defmodule Mix.Tasks.Greet do
  use Mix.Task
  #alias Runnable.Greeting

  @shortdoc "Runs our Greeting.greet/1 function"
  def run(_) do
    Application.ensure_started(:runnable)
    #call_greeting()
  end

  #defp call_greeting do
  #  Greeting.greet "Person"
  #end
end

runnable.ex:

defmodule Runnable do
  @moduledoc """
  Runnable is a sample Elixir application that can easily be run and
  act as an example on how to build different types of Elixir applications
  without using a framework such as Phoenix.
  """
  use Application
  alias Runnable.Greeting

  @doc """
  Start.

  Enables the application to run via `mix run` commands
  """
  def start(_type, _args) do
    #IO.puts "Starting application..."
    log()

    children = [
      Greeting
    ]
    Supervisor.start_link(children, strategy: :one_for_one)
  end

  defp log do
    IO.puts "Starting application..."
  end

end