From e87cf8e14e9903f576e543ab53a1fe28231a2f30 Mon Sep 17 00:00:00 2001 From: Andrew Thompson Date: Thu, 14 Mar 2013 00:32:55 -0400 Subject: [PATCH] Don't use code:load it breaks coverage --- src/lager_app.erl | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/lager_app.erl b/src/lager_app.erl index 7d57f95..b82f041 100644 --- a/src/lager_app.erl +++ b/src/lager_app.erl @@ -95,12 +95,15 @@ expand_handlers([{lager_file_backend, Configs}|T]) -> [ {lager_file_backend:config_to_id(Config), Config} || Config <- Configs] ++ expand_handlers(T); expand_handlers([{Mod, Config}|T]) when is_atom(Mod) -> - %% allow the backend to generate a gen_event handler id, if it wants to - _ = code:load_file(Mod), - Res = case erlang:function_exported(Mod, config_to_id, 1) of - true -> - {Mod:config_to_id(Config), Config}; - false -> + %% Allow the backend to generate a gen_event handler id, if it wants to. + %% We don't use erlang:function_exported here because that requires the module + %% already be loaded, which is unlikely at this phase of startup. Using code:load + %% caused undesireable side-effects with generating code-coverage reports. + Res = try Mod:config_to_id(Config) of + Id -> + {Id, Config} + catch + _:_ -> {Mod, Config} end, [Res | expand_handlers(T)];