Trying to understand why Elixir has a Logger when Lager exists

1,086 views
Skip to first unread message

Jason Harrelson

unread,
Jun 26, 2015, 1:29:08 PM6/26/15
to elixir-l...@googlegroups.com
I am interested in why Elixir has a built in Logger when the Lager project already exists within the Erlang ecosystem?  I am sure there are good reasons, but I cannot find any articles that explain why.  Seems to me that Lager has some pretty killer features, such as the detailed crash reports and the source code line reporting with each statement.  Any help is appreciated as I am evaluating which logger to utilize within a Phoenix application I am working on.

Thanks!

José Valim

unread,
Jun 26, 2015, 1:52:48 PM6/26/15
to elixir-l...@googlegroups.com
Logger also provide crash reports and source code line reporting (just ask the line metadata to be printed). The reason Logger exists is because we want terms and crash reports to be formatted in Elixir terms and syntax and not in Erlang's. Although we agree Lager is great and it was an inspiration when writing Logger, I believe the only big feature in Lager not in Logger is tracing which we hope to be added with Elixir 1.1.



José Valim
Skype: jv.ptec
Founder and Director of R&D

On Fri, Jun 26, 2015 at 7:29 PM, Jason Harrelson <cjhar...@gmail.com> wrote:
I am interested in why Elixir has a built in Logger when the Lager project already exists within the Erlang ecosystem?  I am sure there are good reasons, but I cannot find any articles that explain why.  Seems to me that Lager has some pretty killer features, such as the detailed crash reports and the source code line reporting with each statement.  Any help is appreciated as I am evaluating which logger to utilize within a Phoenix application I am working on.

Thanks!

--
You received this message because you are subscribed to the Google Groups "elixir-lang-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-ta...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-talk/1c66d25e-ed56-4d40-8a22-b4561308d33b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Jason Harrelson

unread,
Jun 26, 2015, 2:12:25 PM6/26/15
to elixir-l...@googlegroups.com, jose....@plataformatec.com.br
Thanks Jose.  I knew you would no waste your time on Logger if there was not a good reason for it.  Can you give me a reference to what metadata is actually available and how to request it (or provide an example)?  I have done a good bit of research today and have read about the subject, but I am still unclear on it.

José Valim

unread,
Jun 26, 2015, 2:19:13 PM6/26/15
to Jason Harrelson, elixir-l...@googlegroups.com
Please check the logger docs:


There is an example with :user_id as metadata. :line is added automatically when you use the Logger macros.


--

Jason Harrelson

unread,
Jun 30, 2015, 4:20:10 PM6/30/15
to elixir-l...@googlegroups.com, jose....@plataformatec.com.br
Jose,

I checked out the docs you recommended (I had read them prior).  After several days of trying to configure the logger in my Phoenix application's dev environment to output metadata, I cannot get the request_id to log.  I also cannot understand from the docs how to add additional custom metadata, etc.  I have followed the instructions at the docs exactly to no avail.  Any additional guidance is greatly appreciated.  Thanks!

Pedro Medeiros

unread,
Jun 30, 2015, 4:23:41 PM6/30/15
to elixir-l...@googlegroups.com
Jason, can you share a project that exemplify the way you are configuring the Logger in the context of your app?


For more options, visit https://groups.google.com/d/optout.



--
Pedro Henrique de Souza Medeiros
----------------------------------
Cel: +55 (61) 9197-0993
Email: pedr...@gmail.com

Beautiful is better than ugly,
Explicit is better than implicit,
Simple is better than complex,
Complex is better than complicated.

The Zen of Python, by Tim Peters

Jason Harrelson

unread,
Jul 1, 2015, 9:22:50 AM7/1/15
to elixir-l...@googlegroups.com
Unfortunately, I cannot share the project as it is on a private server.  However, it is a Phoenix application and following is the contents of my config/dev.exs file.  Notice that I updated the default logging configuration with something very similar to the Elixir Logger docs example (:request_id vs :user_id).

...

config :logger, :console,
  format: "\n$date $time [$level] $metadata$message",
  metadata: [:request_id]

...

I have not made any other changes.  I am confused on what populates the "metadata" data structure.  I am assuming it is most likely a map?  Do I need to add a plug to my pipeline to do this, or some other manual way of populating the metedata data structure?  I checked the conn in a IEx.pry session and did not see anything that was named metadata or looked like it could be the metadata.

Thanks!

José Valim

unread,
Jul 1, 2015, 9:44:59 AM7/1/15
to elixir-l...@googlegroups.com
Which Phoenix version? Do you have a Plug.RequestId in your lib/YOUR_APP/endpoint.ex?



José Valim
Skype: jv.ptec
Founder and Director of R&D

Jason Harrelson

unread,
Jul 1, 2015, 9:51:27 AM7/1/15
to elixir-l...@googlegroups.com, jose....@plataformatec.com.br
Phoenix v0.13.1.  No, there is not a Plug.RequestId in my lib/YOUR_APP/endpoint.ex.  The redacted contents are as follows:

defmodule AppName.Endpoint do
  use Phoenix.Endpoint, otp_app: :app_name

  # Serve at "/" the static files from "priv/static" directory.
  #
  # You should set gzip to true if you are running phoenix.digest
  # when deploying your static files in production.
  plug Plug.Static,
    at: "/", from: : app_name, gzip: false,
    only: ~w(css images js favicon.ico robots.txt)

  # Code reloading can be explicitly enabled under the
  # :code_reloader configuration of your endpoint.
  if code_reloading? do
    plug Phoenix.LiveReloader
    plug Phoenix.CodeReloader
  end

  plug Plug.Logger

  plug Plug.Parsers,
    parsers: [:urlencoded, :multipart, :json],
    pass: ["*/*"],
    json_decoder: Poison

  plug Plug.MethodOverride
  plug Plug.Head

  plug Plug.Session,
    store: :cookie,
    key: "_app_name_key",
    signing_salt: "[REDACTED]"

  plug :router, AppName.Router
end

Thanks

José Valim

unread,
Jul 1, 2015, 9:57:17 AM7/1/15
to Jason Harrelson, elixir-l...@googlegroups.com
Just to be sure, please add

    plug Plug.RequestId

Before Plug.Logger and let me know how it goes.



José Valim
Skype: jv.ptec
Founder and Director of R&D

Jason Harrelson

unread,
Jul 1, 2015, 10:07:49 AM7/1/15
to elixir-l...@googlegroups.com, jose....@plataformatec.com.br
That did it.  It must not have made it into the endpoint template for v0.13.1.

I do see where the endpoint template has been updated: https://github.com/phoenixframework/phoenix/blob/c6b336be2104989c4c4eb36b6288d537c9369316/installer/templates/new/lib/application_name/endpoint.ex#L19. However, I cannot find where Plug.RequestId is defined in the Phoenix source.  I would like to examine it to see how it works if you can give me a link to it.  In addition, I took a look at the conn in the controller and still do not see anything that looks like the metadata that is used in the logger.  Where is this data stored?

As always, thanks for your help!

Jason Harrelson

unread,
Jul 1, 2015, 10:33:05 AM7/1/15
to elixir-l...@googlegroups.com, jose....@plataformatec.com.br
Nevermind my last set of questions. I finally located the Plug.RequstId in the elixir-lang repo: https://github.com/elixir-lang/plug/blob/master/lib/plug/request_id.ex.  I incorrectly assumed it was defined in the Phoenix repo.  The source code there will answer my remaining questions.

Lance Halvorsen

unread,
Jul 1, 2015, 10:37:50 AM7/1/15
to elixir-l...@googlegroups.com
Hi Jason,

Plug.RequestId is defined in Plug itself, not Phoenix. Here's a link:
.L

Jason Harrelson

unread,
Jul 1, 2015, 10:58:52 AM7/1/15
to elixir-l...@googlegroups.com
OK, everything is working now.  However, If I use the Logger inside of a module that is not a controller or plug, the metadata is empty, so of course it does not get output for those specific logging statements.  Is this anticipated behavior?  Is there a workaround besides passing the request_id value to any modules that need to use the Logger?

Thanks

Ben Wilson

unread,
Jul 1, 2015, 11:08:25 AM7/1/15
to elixir-l...@googlegroups.com
If I recall correctly the meta-data is stored on the process dictionary, which is to say it matters what process you're in not what module.
Reply all
Reply to author
Forward
0 new messages