Generate variable names with a function, suggested by @mshonle
diff --git a/src/lager_transform.erl b/src/lager_transform.erl
index e7f8f35..30364ee 100644
--- a/src/lager_transform.erl
+++ b/src/lager_transform.erl
@@ -135,9 +135,9 @@
end,
%% Generate some unique variable names so we don't accidentaly export from case clauses.
%% Note that these are not actual atoms, but the AST treats variable names as atoms.
- LevelVar = list_to_atom("__Level" ++ atom_to_list(get(module)) ++ integer_to_list(Line)),
- TracesVar = list_to_atom("__Traces" ++ atom_to_list(get(module)) ++ integer_to_list(Line)),
- PidVar = list_to_atom("__Pid" ++ atom_to_list(get(module)) ++ integer_to_list(Line)),
+ LevelVar = make_varname("__Level", Line),
+ TracesVar = make_varname("__Traces", Line),
+ PidVar = make_varname("__Pid", Line),
%% Wrap the call to lager_dispatch log in a case that will avoid doing any work if this message is not elegible for logging
%% case {whereis(lager_event(lager_event), lager_config:get(loglevel, {?LOG_NONE, []})} of
{'case', Line,
@@ -198,6 +198,9 @@
transform_statement(Stmt) ->
Stmt.
+make_varname(Prefix, Line) ->
+ list_to_atom(Prefix ++ atom_to_list(get(module)) ++ integer_to_list(Line)).
+
%% concat 2 list ASTs by replacing the terminating [] in A with the contents of B
concat_lists({var, Line, _Name}=Var, B) ->
%% concatenating a var with a cons