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.

68 lines
1.9 KiB

4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
  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. -module(lager_crash_backend).
  17. -include("eRum.hrl").
  18. -behaviour(gen_event).
  19. -export([init/1, handle_call/2, handle_event/2, handle_info/2, terminate/2,
  20. code_change/3]).
  21. -ifdef(TEST).
  22. -include_lib("eunit/include/eunit.hrl").
  23. -endif.
  24. init([CrashBefore, CrashAfter]) ->
  25. case is_tuple(CrashBefore) andalso (timer:now_diff(CrashBefore, os:timestamp()) > 0) of
  26. true ->
  27. %?debugFmt("crashing!~n", []),
  28. {error, crashed};
  29. _ ->
  30. %?debugFmt("Not crashing!~n", []),
  31. case is_tuple(CrashAfter) of
  32. true ->
  33. CrashTime = timer:now_diff(CrashAfter, os:timestamp()) div 1000,
  34. case CrashTime > 0 of
  35. true ->
  36. %?debugFmt("crashing in ~p~n", [CrashTime]),
  37. erlang:send_after(CrashTime, self(), crash),
  38. {ok, {}};
  39. _ -> {error, crashed}
  40. end;
  41. _ ->
  42. {ok, {}}
  43. end
  44. end.
  45. handle_call(_Request, State) ->
  46. {ok, ok, State}.
  47. handle_event(_Event, State) ->
  48. {ok, State}.
  49. handle_info(crash, _State) ->
  50. %?debugFmt("Time to crash!~n", []),
  51. crash;
  52. handle_info(_Info, State) ->
  53. {ok, State}.
  54. terminate(_Reason, _State) ->
  55. ok.
  56. code_change(_OldVsn, State, _Extra) ->
  57. {ok, State}.