Always got undef error of lager_transform when using lager log framework
Asked Answered
G

2

5

I want to use lager as my log utility and I have orgnazied my proj as below:

proj\
  |
  |--lager\
  |    |--src\
  |    |--ebin\
  |    |--...
  |     
  |--logserver\
  |    |--src\
  |    |--ebin\
  |    |--rebar.config
  |    |--...
  |
  |--rebar
  |

However, when I try to compile logserver, I always got the following error:

D:\proj\logserver>..\rebar compile

==> logserver (compile)
src/logserver_app.erl:none: error in parse transform 'lager_transform': {undef,
                                             [{lager_transform,
                                               parse_transform,
                                               [[{attribute,1,file,
                                                  {"src/logserver_app.erl",1}},  
                                                  ...

Can anyone know the reason? Thanks!

These is some additional information:

  • I am using Windows OS and using latest version of Erlang and rebar and lager.
  • lager itself has already been compiled. We can find the D:\proj\logserver>dir ..\lager\ebin\lager_transform.beam (This will succeed)
  • rebar's config file(D:\proj\logserver\rebar.config):

    ... {erl_opts, [{parse_transform, lager_transform}, debug_info,{d,'TEST'}, {i, "include"}, {src_dirs, ["src"]}]}.

    {lib_dirs, ["..\lager\ebin"]}. ...

Gravimeter answered 8/9, 2012 at 7:30 Comment(0)
F
6

If you already have lager in your deps then make sure that you move lager dependency first in rebar.config so that way it will compile first. Like so:

{deps,[
  lager,
  ..
]}.
Fearless answered 5/7, 2013 at 8:38 Comment(0)
D
4

Did you add lager as a dependency in your rebar.config? I guess lager is not in the path.

From the rebar wiki:

To use lager in your application, you need to define it as a rebar dep or have some other way of including it in erlang’s path. You can then add the following option to the erlang compiler flags:

{parse_transform, lager_transform}

You can add 'lager' as a dependency by editing your rebar.config:

%% == Dependencies ==

%% Where to put any downloaded dependencies. Default is "deps"
{deps_dir, "deps"}.

%% What dependencies we have, dependencies can be of 3 forms, an application
%% name as an atom, eg. mochiweb, a name and a version (from the .app file), or
%% an application name, a version and the SCM details on how to fetch it (SCM
%% type, location and revision). Rebar currently supports git, hg, bzr and svn.
{deps, [application_name,
        {application_name, "1.0.*"},
        {application_name, "1.0.*",
         {git, "git://github.com/basho/rebar.git", {branch, "master"}}}]}.

In your case, that should be something like:

{deps, [{lager, ".*", {git, "git://github.com/basho/lager.git", "HEAD"}}]}.

More info about the rebar dependency manager here:

https://github.com/basho/rebar/wiki/Dependency-management

Debutante answered 10/9, 2012 at 10:32 Comment(4)
Thanks. But my lager is located in my local directory. So how can I add it as a dependency ?Gravimeter
Just added rebar configuration for lager.Debutante
I have been having similar issues. I have tried above suggestions with no success. see this :#20814013Christianize
I'm total dumb with rebar3, but the foggy part for me was to catch where the "erlang compiler flags" were located according to rebar3.Turned out I had to change a line in rebar.config from this{erl_opts, [debug_info]}. to this {erl_opts, [debug_info, {parse_transform, lager_transform}]}.Howitzer

© 2022 - 2024 — McMap. All rights reserved.