Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

103 Zeilen
3.1 KiB

vor 14 Jahren
vor 14 Jahren
vor 14 Jahren
vor 14 Jahren
vor 14 Jahren
vor 14 Jahren
vor 14 Jahren
  1. %% Copyright (c) 2011-2012 Basho Technologies, Inc. All Rights Reserved.
  2. %%
  3. %% This file is provided to you under the Apache License,
  4. %% Version 2.0 (the "License"); you may not use this file
  5. %% except in compliance with the License. You may obtain
  6. %% a copy of the License at
  7. %%
  8. %% http://www.apache.org/licenses/LICENSE-2.0
  9. %%
  10. %% Unless required by applicable law or agreed to in writing,
  11. %% software distributed under the License is distributed on an
  12. %% "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  13. %% KIND, either express or implied. See the License for the
  14. %% specific language governing permissions and limitations
  15. %% under the License.
  16. -define(DEFAULT_TRUNCATION, 4096).
  17. -define(DEFAULT_TRACER, lager_default_tracer).
  18. -define(DEFAULT_SINK, lager_event).
  19. -define(LEVELS,
  20. [debug, info, notice, warning, error, critical, alert, emergency, none]).
  21. -define(DEBUG, 128).
  22. -define(INFO, 64).
  23. -define(NOTICE, 32).
  24. -define(WARNING, 16).
  25. -define(ERROR, 8).
  26. -define(CRITICAL, 4).
  27. -define(ALERT, 2).
  28. -define(EMERGENCY, 1).
  29. -define(LOG_NONE, 0).
  30. -define(LEVEL2NUM(Level),
  31. case Level of
  32. debug -> ?DEBUG;
  33. info -> ?INFO;
  34. notice -> ?NOTICE;
  35. warning -> ?WARNING;
  36. error -> ?ERROR;
  37. critical -> ?CRITICAL;
  38. alert -> ?ALERT;
  39. emergency -> ?EMERGENCY
  40. end).
  41. -define(NUM2LEVEL(Num),
  42. case Num of
  43. ?DEBUG -> debug;
  44. ?INFO -> info;
  45. ?NOTICE -> notice;
  46. ?WARNING -> warning;
  47. ?ERROR -> error;
  48. ?CRITICAL -> critical;
  49. ?ALERT -> alert;
  50. ?EMERGENCY -> emergency
  51. end).
  52. -define(SHOULD_LOG(Level),
  53. (lager_util:level_to_num(Level) band element(1, lager_config:get(loglevel, {?LOG_NONE, []}))) /= 0).
  54. -define(NOTIFY(Level, Pid, Format, Args),
  55. gen_event:notify(lager_event, {log, lager_msg:new(io_lib:format(Format, Args),
  56. Level,
  57. [{pid,Pid},{line,?LINE},{file,?FILE},{module,?MODULE}],
  58. [])}
  59. )).
  60. %% FOR INTERNAL USE ONLY
  61. %% internal non-blocking logging call
  62. %% there's some special handing for when we try to log (usually errors) while
  63. %% lager is still starting.
  64. -ifdef(TEST).
  65. -define(INT_LOG(Level, Format, Args),
  66. case ?SHOULD_LOG(Level) of
  67. true ->
  68. ?NOTIFY(Level, self(), Format, Args);
  69. _ ->
  70. ok
  71. end).
  72. -else.
  73. -define(INT_LOG(Level, Format, Args),
  74. Self = self(),
  75. %% do this in a spawn so we don't cause a deadlock calling gen_event:which_handlers
  76. %% from a gen_event handler
  77. spawn(fun() ->
  78. case catch(gen_event:which_handlers(lager_event)) of
  79. X when X == []; X == {'EXIT', noproc}; X == [lager_backend_throttle] ->
  80. %% there's no handlers yet or lager isn't running, try again
  81. %% in half a second.
  82. timer:sleep(500),
  83. ?NOTIFY(Level, Self, Format, Args);
  84. _ ->
  85. case ?SHOULD_LOG(Level) of
  86. true ->
  87. ?NOTIFY(Level, Self, Format, Args);
  88. _ ->
  89. ok
  90. end
  91. end
  92. end)).
  93. -endif.