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 lines
3.1 KiB

14 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. %% @doc Lager's top level supervisor.
  17. %% @private
  18. -module(lager_sup).
  19. -behaviour(supervisor).
  20. %% API
  21. -export([start_link/0]).
  22. %% Callbacks
  23. -export([init/1]).
  24. start_link() ->
  25. supervisor:start_link({local, ?MODULE}, ?MODULE, []).
  26. init([]) ->
  27. %% set up the config, is safe even during relups
  28. lager_config:new(),
  29. %% TODO:
  30. %% Always start lager_event as the default and make sure that
  31. %% other gen_event stuff can start up as needed
  32. %%
  33. %% Maybe a new API to handle the sink and its policy?
  34. Children = [
  35. {lager, {gen_event, start_link, [{local, lager_event}]},
  36. permanent, 5000, worker, [dynamic]},
  37. {lager_handler_watcher_sup, {lager_handler_watcher_sup, start_link, []},
  38. permanent, 5000, supervisor, [lager_handler_watcher_sup]}],
  39. %% check if the crash log is enabled
  40. Crash = case application:get_env(lager, crash_log) of
  41. {ok, undefined} ->
  42. [];
  43. {ok, false} ->
  44. [];
  45. {ok, File} ->
  46. MaxBytes = case application:get_env(lager, crash_log_msg_size) of
  47. {ok, Val} when is_integer(Val) andalso Val > 0 -> Val;
  48. _ -> 65536
  49. end,
  50. RotationSize = case application:get_env(lager, crash_log_size) of
  51. {ok, Val1} when is_integer(Val1) andalso Val1 >= 0 -> Val1;
  52. _ -> 0
  53. end,
  54. RotationCount = case application:get_env(lager, crash_log_count) of
  55. {ok, Val2} when is_integer(Val2) andalso Val2 >=0 -> Val2;
  56. _ -> 0
  57. end,
  58. RotationDate = case application:get_env(lager, crash_log_date) of
  59. {ok, Val3} ->
  60. case lager_util:parse_rotation_date_spec(Val3) of
  61. {ok, Spec} -> Spec;
  62. {error, _} when Val3 == "" -> undefined; %% blank is ok
  63. {error, _} ->
  64. error_logger:error_msg("Invalid date spec for "
  65. "crash log ~p~n", [Val3]),
  66. undefined
  67. end;
  68. _ -> undefined
  69. end,
  70. [{lager_crash_log, {lager_crash_log, start_link, [File, MaxBytes,
  71. RotationSize, RotationDate, RotationCount]},
  72. permanent, 5000, worker, [lager_crash_log]}];
  73. _ ->
  74. []
  75. end,
  76. {ok, {{one_for_one, 10, 60},
  77. Children ++ Crash
  78. }}.