Skip to content

Latest commit

History

66 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

Elixir Function Decorator

A function decorator macro for Elixir. Used mainly for adding log statements to the function calls.

This project is based mainly on:

Motivation

All I did was use the solution provided by the mentioned above, add some minor refactoring and adjustments for my needs and package it as an helper module.

This was a learning project getting into Elixir macros field.

For getting into Elixir Macros, you are encouraged to read Saša Jurić 's excellent Elixir macro articles series

State

  • Currently in alpha stage.
  • Not intended to be used in production. Only for experiments.
  • For logging, one can use other means like trace.

Installation

The package can be installed as:

  1. Add function_decorating to your list of dependencies in mix.exs:

    def deps do [{:function_decorating, "~> 0.0.6"}] end

  2. Ensure function_decorating is started before your application:

    def application do [applications: [:function_decorating]] end

Usage

Decorating in dev with log decorator.

defmoduleUserdouseFunctionDecoratingdecorate_fn_with(LogDecorator)defsay(word)dowordendend
iex>User.say("hello")#PID<0.86.0> [x] Elixir.User.say(["hello"]) -> "hello""hello"

Default usage is for Mix.env == :dev only. To override it:

defmoduleUserdouseFunctionDecoratingmix_envs: [:test]decorate_fn_with(LogDecorator)defsay(word)dowordendend
iex>Mix.env:testiex>User.say("hello")#PID<0.86.0> [x] Elixir.User.say(["hello"]) -> "hello""hello"

About

A function decorator macro for Elixir. Used mainly for adding log statements to function calls.

Resources

Stars

3 stars

Watchers

2 watching

Forks

Releases

Packages

Contributors

Languages