PageRenderTime 29ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/ucengine/src/core/uce_log.erl

http://github.com/AF83/ucengine
Erlang | 64 lines | 35 code | 12 blank | 17 comment | 0 complexity | 605df99013dc1259b5741277376e0c19 MD5 | raw file
  1. %%
  2. %% U.C.Engine - Unified Collaboration Engine
  3. %% Copyright (C) 2011 af83
  4. %%
  5. %% This program is free software: you can redistribute it and/or modify
  6. %% it under the terms of the GNU Affero General Public License as published by
  7. %% the Free Software Foundation, either version 3 of the License, or
  8. %% (at your option) any later version.
  9. %%
  10. %% This program is distributed in the hope that it will be useful,
  11. %% but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. %% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. %% GNU Affero General Public License for more details.
  14. %%
  15. %% You should have received a copy of the GNU Affero General Public License
  16. %% along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. %%
  18. -module(uce_log).
  19. -export([debug/3, info/3, warning/3, error/3, critical/3]).
  20. debug(Format, ML, Args) ->
  21. log(debug, info_msg, "DEBUG: ~p:~p: ", Format, ML, Args).
  22. info(Format, ML, Args) ->
  23. log(info, info_msg, "~p:~p: ", Format, ML, Args).
  24. warning(Format, ML, Args) ->
  25. log(warning, warning_msg, "~p:~p: ", Format, ML, Args).
  26. error(Format, ML, Args) ->
  27. log(error, error_msg, "~p:~p: ", Format, ML, Args).
  28. critical(Format, ML, Args) ->
  29. log(critical, critical_msg, "~p:~p: ", Format, ML, Args).
  30. current_level(debug) ->
  31. 1;
  32. current_level(info) ->
  33. 2;
  34. current_level(warning) ->
  35. 3;
  36. current_level(error) ->
  37. 4;
  38. current_level(critical) ->
  39. 5.
  40. log(Level, Fun, Pre, Format, ML, Args) ->
  41. log(current_level(Level), current_level(config:get(log_level)), Fun, Pre, Format, ML, Args).
  42. log(Level, ConfigLevel, Fun, Pre, Format, [Module, Line], Args) when Level >= ConfigLevel ->
  43. error_logger:Fun(Pre ++ Format, [Module, Line] ++ Args);
  44. log(_Level, _Configlevel, _Fun, _Pre, _Format, [_Module, _Line], _Args) ->
  45. ok.
  46. -ifdef(TEST).
  47. -include_lib("eunit/include/eunit.hrl").
  48. current_level_test() ->
  49. lists:foreach(fun({Level, Expected}) ->
  50. ?assertEqual(Expected, current_level(Level))
  51. end, [{debug, 1}, {info, 2}, {warning, 3}, {error, 4}, {critical, 5}]).
  52. -endif.