Search code examples
unit-testingerlangrebareunit

Erlang rebar, kernel options


I am trying to write simple erlang application, using rebar as eunit test runner. Is there any way to redirect annoying log messages into file, without doing it programmatically? Without rebar I can say erl -kernel error_logger "{file,\"test.log\"}" to do this, but how I can do it with rebar?

Generalizinig the question, is there any way to pass some application environment settings using rebar, when running tests?


Solution

  • Answering to my own question. As discussed here, there is a way to pass erlang flags to rebar using ERL_AFLAGS environment variable. So it's possible to create config file with all necessary environment settings, and say ERL_AFLAGS="-config /path/to/config" rebar eunit.

    Solution of my problem is:

    echo '[{kernel, [{error_logger, {file, "test.log"}}]}].' > eunit.config
    ERL_AFLAGS="-config eunit" rebar eunit
    

    Think it is clumsy approach, but it just works.