@@ -58,8 +58,17 @@ defmodule Logger.Watcher do
58
58
@ doc false
59
59
def init ( { mod , handler , args , :monitor } ) do
60
60
ref = Process . monitor ( mod )
61
+ res = GenEvent . add_handler ( mod , handler , args , monitor: true )
62
+ do_init ( res , mod , handler , ref )
63
+ end
64
+
65
+ def init ( { mod , handler , args , :link } ) do
66
+ res = :gen_event . add_sup_handler ( mod , handler , args )
67
+ do_init ( res , mod , handler , nil )
68
+ end
61
69
62
- case GenEvent . add_handler ( mod , handler , args , monitor: true ) do
70
+ defp do_init ( res , mod , handler , ref ) do
71
+ case res do
63
72
:ok ->
64
73
{ :ok , { mod , handler , ref } }
65
74
{ :error , :ignore } ->
@@ -73,18 +82,6 @@ defmodule Logger.Watcher do
73
82
end
74
83
end
75
84
76
- def init ( { mod , handler , args , :link } ) do
77
- case :gen_event . add_sup_handler ( mod , handler , args ) do
78
- :ok ->
79
- { :ok , { mod , handler , nil } }
80
- { :error , :ignore } ->
81
- send ( self ( ) , { :gen_event_EXIT , handler , :normal } )
82
- { :ok , { mod , handler , nil } }
83
- { :error , reason } ->
84
- { :stop , reason }
85
- end
86
- end
87
-
88
85
@ doc false
89
86
def handle_info ( { :gen_event_EXIT , handler , reason } , { _ , handler , _ } = state )
90
87
when reason in [ :normal , :shutdown ] do
0 commit comments