rewrite from lager
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

89 line
2.7 KiB

4 年之前
4 年之前
4 年之前
4 年之前
4 年之前
4 年之前
4 年之前
4 年之前
4 年之前
4 年之前
4 年之前
4 年之前
4 年之前
4 年之前
4 年之前
4 年之前
4 年之前
4 年之前
4 年之前
4 年之前
4 年之前
4 年之前
4 年之前
4 年之前
4 年之前
4 年之前
4 年之前
4 年之前
4 年之前
4 年之前
4 年之前
4 年之前
  1. %%
  2. %% %CopyrightBegin%
  3. %%
  4. %% Copyright Ericsson AB 1996-2009. All Rights Reserved.
  5. %%
  6. %% The contents of this file are subject to the Erlang Public License,
  7. %% Version 1.1, (the "License"); you may not use this file except in
  8. %% compliance with the License. You should have received a copy of the
  9. %% Erlang Public License along with this software. If not, it can be
  10. %% retrieved online at http://www.erlang.org/.
  11. %%
  12. %% Software distributed under the License is distributed on an "AS IS"
  13. %% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
  14. %% the License for the specific language governing rights and limitations
  15. %% under the License.
  16. %%
  17. %% %CopyrightEnd%
  18. %%
  19. -module(sync_error_logger).
  20. %% The error_logger API, but synchronous!
  21. %% This is helpful for tests, otherwise you need lots of nasty timer:sleep.
  22. %% Additionally, the warning map can be set on a per-process level, for
  23. %% convienience, via the process dictionary value `warning_map'.
  24. -export([
  25. info_msg/1, info_msg/2,
  26. warning_msg/1, warning_msg/2,
  27. error_msg/1, error_msg/2
  28. ]).
  29. -export([
  30. info_report/1, info_report/2,
  31. warning_report/1, warning_report/2,
  32. error_report/1, error_report/2
  33. ]).
  34. info_msg(Format) ->
  35. info_msg(Format, []).
  36. info_msg(Format, Args) ->
  37. gen_event:sync_notify(error_logger, {info_msg, group_leader(), {self(), Format, Args}}).
  38. warning_msg(Format) ->
  39. warning_msg(Format, []).
  40. warning_msg(Format, Args) ->
  41. gen_event:sync_notify(error_logger, {warning_msg_tag(), group_leader(), {self(), Format, Args}}).
  42. error_msg(Format) ->
  43. error_msg(Format, []).
  44. error_msg(Format, Args) ->
  45. gen_event:sync_notify(error_logger, {error, group_leader(), {self(), Format, Args}}).
  46. info_report(Report) ->
  47. info_report(std_info, Report).
  48. info_report(Type, Report) ->
  49. gen_event:sync_notify(error_logger, {info_report, group_leader(), {self(), Type, Report}}).
  50. warning_report(Report) ->
  51. warning_report(std_warning, Report).
  52. warning_report(Type, Report) ->
  53. {Tag, NType} = warning_report_tag(Type),
  54. gen_event:sync_notify(error_logger, {Tag, group_leader(), {self(), NType, Report}}).
  55. error_report(Report) ->
  56. error_report(std_error, Report).
  57. error_report(Type, Report) ->
  58. gen_event:sync_notify(error_logger, {error_report, group_leader(), {self(), Type, Report}}).
  59. warning_msg_tag() ->
  60. case get(warning_map) of
  61. warning -> warning_msg;
  62. info -> info_msg;
  63. _ -> error
  64. end.
  65. warning_report_tag(Type) ->
  66. case {get(warning_map), Type == std_warning} of
  67. {warning, _} -> {warning_report, Type};
  68. {info, true} -> {info_report, std_info};
  69. {info, false} -> {info_report, Type};
  70. {_, true} -> {error_report, std_error};
  71. {_, false} -> {error_report, Type}
  72. end.