sheharyarn
Why is Logger composed of Macros?
Had to use Logger in one of my applications today, and remembered that I needed to call require first. So I decided to look at the Logger source code to see why debug, info, error, etc. are macros and not simple functions.
From the code, the macros for debug, info, etc (and even their underlying functions) look very simple. Wasn’t it possible to simply export them as methods instead of macros?
Parallel StackOverflow Question:
http://stackoverflow.com/questions/40198502/why-is-logger-composed-of-macros
Marked As Solved
josevalim
The answer on stack overflow is correct. It is a macro so it gets metadata about the caller, such as file, line, module, function, app, etc. This metadata may be logged and it may be used in the future for tracing/filtering.
That was the original motivation anyway. The compile time purging came later.
Also Liked
KronicDeth
It’s so the entire Logger call can be stripped out of the code at compile time if you use :compile_time_purge_level.
OvermindDL1
As I recall it is to allow the code to just entirely not exist for logging levels that you do not want, so the code is never even called and incurs no speed penalty, thus you only pay for the logging levels that you are actively logging. ![]()
Popular in Questions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance









