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.

88 lines
3.2 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
  1. -module(eLog_sup).
  2. -behaviour(supervisor).
  3. -include("eLog.hrl").
  4. -include("lgDef.hrl").
  5. -export([
  6. start_link/0
  7. ]).
  8. -export([
  9. init/1
  10. ]).
  11. start_link() ->
  12. supervisor:start_link({local, ?MODULE}, ?MODULE, []).
  13. % 主管的孩子被定义为孩子规格列表 。当主管启动时,将根据此列表从左到右依次启动子进程。主管终止时,它首先以相反的启动顺序从右到左终止其子进程。
  14. % sup_flags() =
  15. % #{
  16. % strategy => strategy(), % optional one_for_one | one_for_all | rest_for_one | simple_one_for_one
  17. % intensity => non_neg_integer(), % optional MaxR 周期时间内最大重启次数
  18. % period => pos_integer() % optional MaxT 重启时间周期 MaxT里重启次数大于MaxR
  19. % }
  20. % child_spec() =
  21. % #{
  22. % id => child_id(), % mandatory Id用来内部标识子规范
  23. % start => mfargs(), % mandatory {M,F,A}
  24. % restart => restart(), % optional permanent(总是重启) | transient(异常关闭会重启即关闭原因非 normal,shutdown,{shutdown,Term}) | temporary(不会重启)
  25. % shutdown => shutdown(), % optional brutal_kill | infinity | integer
  26. % type => worker(), % optional supervisor | worker
  27. % modules => modules() % optional [Module] 假如子进程是supervisor、gen_server 或 gen_fsm,那么Module 是回调模块的名称;假如子进程是gen_event,那么Modules 应该是dynamic
  28. % }
  29. init(_Args) ->
  30. %% set up the config, is safe even during relups
  31. ?eLogInit(),
  32. %%始终将lgEvent作为默认值启动,并确保可以根据需要启动其他gen_event东西也许是一个用于处理接收器及其策略的新API?
  33. SupFlags =
  34. #{
  35. strategy => one_for_one,
  36. intensity => 10,
  37. period => 60
  38. },
  39. LgEventSpec = #{
  40. id => lgEvent,
  41. start => {gen_emm, start_link, [{local, lgEvent}]},
  42. restart => permanent,
  43. shutdown => 5000,
  44. type => worker,
  45. modules => [dynamic]
  46. },
  47. LgHWatcherSupSpec = #{
  48. id => lgHWatcherSup,
  49. start => {lgHWatcherSup, start_link, []},
  50. restart => permanent,
  51. shutdown => 5000,
  52. type => supervisor,
  53. modules => [lgHWatcherSup]
  54. },
  55. ChildSpecs =
  56. case lgUtil:get_env(crashLogFile, false) of
  57. false ->
  58. [LgEventSpec, LgHWatcherSupSpec];
  59. File ->
  60. MsgMaxBytes = lgUtil:get_env(crashLogMsgSize, 65536),
  61. RotationSize = lgUtil:get_env(crashLogFileSize, 0),
  62. RotationCount = lgUtil:get_env(crashLogCount, 0),
  63. RotationDate = lgUtil:get_env(crashLogDate, "$D0"),
  64. RotationMod = lgUtil:get_env(crashLogRotator, ?LgDefRotateMod),
  65. CrashLogSpec = #{
  66. id => lgCrashLog,
  67. start => {lgCrashLog, start_link, [File, MsgMaxBytes, RotationSize, RotationDate, RotationCount, RotationMod]},
  68. restart => permanent,
  69. shutdown => 5000,
  70. type => worker,
  71. modules => [lgCrashLog]
  72. },
  73. [LgEventSpec, LgHWatcherSupSpec, CrashLogSpec]
  74. end,
  75. {ok, {SupFlags, ChildSpecs}}.