Created
April 24, 2017 15:55
-
-
Save am-kantox/a506fab1aac2d5d314aee15454751444 to your computer and use it in GitHub Desktop.
Making a sibling for lazy Elixir `Logger`
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule Eventory.Helpers.Log do | |
@moduledoc false | |
Enum.each(~w|error info warn debug|a, fn level -> | |
Module.register_attribute(__MODULE__, :level, persist: false) | |
Module.put_attribute(__MODULE__, :level, level) | |
defmacro unquote(Module.get_attribute(__MODULE__, :level))(chardata_or_fun, metadata \\ []) do | |
{{:., [], [ | |
{:__aliases__, [alias: false], [:Logger]}, | |
unquote(Module.get_attribute(__MODULE__, :level))]}, | |
[], | |
[chardata_or_fun, metadata]} | |
end | |
Module.delete_attribute(__MODULE__, :level) | |
end) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment