2727 terminate /2 , code_change /3 ]).
2828-export_type ([handle / 0 , upstream_opts / 0 ]).
2929
30- -include_lib (" hut /include/hut .hrl" ).
30+ -include_lib (" kernel /include/logger .hrl" ).
3131
3232-define (SERVER , ? MODULE ).
3333-define (APP , mtproto_proxy ).
@@ -129,12 +129,12 @@ handle_call({set_config, Name, Value}, _From, State) ->
129129 {{ok , State # state .backpressure_conf },
130130 State # state {backpressure_conf = BpConfig }}
131131 catch Type :Reason ->
132- ? log ( error , " ~p : not updating downstream_backpressure: ~p " ,
132+ ? LOG_ERROR ( " ~p : not updating downstream_backpressure: ~p " ,
133133 [Type , Reason ]),
134134 {ignored , State }
135135 end ;
136136 _ ->
137- ? log ( warning , " set_config ~p =~p ignored" , [Name , Value ]),
137+ ? LOG_WARNING ( " set_config ~p =~p ignored" , [Name , Value ]),
138138 {ignored , State }
139139 end ,
140140 {reply , Response , State1 }.
@@ -164,8 +164,8 @@ handle_info(do_connect, #state{dc_id = DcId} = State) ->
164164 {ok , St1 } = connect (DcId , State ),
165165 {noreply , St1 }
166166 catch Class :Reason :Stack ->
167- ? log ( error , " Down connect to dc=~w error: ~s " ,
168- [DcId , lager : pr_stacktrace ( Stack , { Class , Reason } )]), % XXX lager-specific
167+ ? LOG_ERROR ( " Down connect to dc=~w error: ~s " ,
168+ [DcId , erl_error : format_exception ( Class , Reason , Stack )]),
169169 erlang :send_after (300 , self (), do_connect ),
170170 {noreply , State }
171171 end ;
@@ -182,7 +182,7 @@ handle_info(handshake_timeout, #state{stage = Stage, dc_id = DcId} = St) ->
182182
183183terminate (_Reason , # state {upstreams = Ups }) ->
184184 % % Should I do this or dc_pool? Maybe only when reason is 'normal'?
185- ? log ( warning , " Downstream terminates with reason ~p ; len(upstreams)=~p " ,
185+ ? LOG_WARNING ( " Downstream terminates with reason ~p ; len(upstreams)=~p " ,
186186 [_Reason , map_size (Ups )]),
187187 Self = self (),
188188 lists :foreach (
@@ -201,7 +201,7 @@ handle_send(Data, Upstream, #state{upstreams = Ups,
201201 Packet = mtp_rpc :encode_packet ({data , Data }, {UpstreamStatic , ProxyAddr }),
202202 down_send (Packet , St );
203203 _ ->
204- ? log ( warning , " Upstream=~p not found" , [Upstream ]),
204+ ? LOG_WARNING ( " Upstream=~p not found" , [Upstream ]),
205205 {{error , unknown_upstream }, St }
206206 end .
207207
@@ -214,7 +214,7 @@ handle_upstream_new(Upstream, Opts, #state{upstreams = Ups,
214214 UpsStatic = {ConnId , iolist_to_binary (mtp_rpc :encode_ip_port (Ip , Port )), AdTag },
215215 Ups1 = Ups #{Upstream => {UpsStatic , 0 , 0 }},
216216 UpsRev1 = UpsRev #{ConnId => Upstream },
217- ? log ( debug , " New upstream=~p conn_id=~p " , [Upstream , ConnId ]),
217+ ? LOG_DEBUG ( " New upstream=~p conn_id=~p " , [Upstream , ConnId ]),
218218 St # state {upstreams = Ups1 ,
219219 upstreams_rev = UpsRev1 }.
220220
@@ -232,7 +232,7 @@ handle_upstream_closed(Upstream, #state{upstreams = Ups,
232232 down_send (Packet , St2 );
233233 error ->
234234 % % It happens when we get rpc_close_ext
235- ? log ( info , " Unknown upstream ~p " , [Upstream ]),
235+ ? LOG_INFO ( " Unknown upstream ~p " , [Upstream ]),
236236 {ok , St }
237237 end .
238238
@@ -282,13 +282,13 @@ handle_rpc({close_ext, ConnId}, St) ->
282282 St2 # state {upstreams = Ups1 ,
283283 upstreams_rev = UpsRev1 };
284284 error ->
285- ? log ( warning , " Unknown upstream ~p " , [ConnId ]),
285+ ? LOG_WARNING ( " Unknown upstream ~p " , [ConnId ]),
286286 St1
287287 end ;
288288handle_rpc ({simple_ack , ConnId , Confirm }, S ) ->
289289 up_send ({simple_ack , self (), Confirm }, ConnId , S );
290290handle_rpc ({unknown , Tag , Tail }, S ) ->
291- ? log ( info , " Unknown packet from backend. Tag ~w , tail: ~w " , [Tag , Tail ]),
291+ ? LOG_INFO ( " Unknown packet from backend. Tag ~w , tail: ~w " , [Tag , Tail ]),
292292 S .
293293
294294
@@ -318,7 +318,7 @@ up_send(Packet, ConnId, #state{upstreams_rev = UpsRev} = St) ->
318318 St
319319 end ;
320320 error ->
321- ? log ( warning , " Unknown connection_id=~w " , [ConnId ]),
321+ ? LOG_WARNING ( " Unknown connection_id=~w " , [ConnId ]),
322322 % % WHY!!!?
323323 % % ClosedPacket = mtp_rpc:encode_packet(remote_closed, ConnId),
324324 % % {ok, St1} = down_send(ClosedPacket, St),
@@ -460,7 +460,7 @@ connect(DcId, S) ->
460460 mtp_metric :count_inc ([? APP , out_connect_ok , total ], 1 ,
461461 #{labels => [DcId ]}),
462462 AddrStr = inet :ntoa (Host ),
463- ? log ( info , " ~s :~p : TCP connected" , [AddrStr , Port ]),
463+ ? LOG_INFO ( " ~s :~p : TCP connected" , [AddrStr , Port ]),
464464 down_handshake1 (S # state {sock = Sock ,
465465 netloc = {Host , Port }});
466466 {error , Reason } = Err ->
@@ -558,7 +558,7 @@ down_handshake3(Pkt, #state{stage_state = {Deadline, PrevSenderPid}, pool = Pool
558558 {handshake , _SenderPid , PeerPid } = mtp_rpc :decode_handshake (Pkt ),
559559 (PeerPid == PrevSenderPid ) orelse error ({wrong_sender_pid , PeerPid }),
560560 ok = mtp_dc_pool :ack_connected (Pool , self ()),
561- ? log ( info , " ~s :~w : dc=~w handshake complete" , [inet :ntoa (Addr ), Port , DcId ]),
561+ ? LOG_INFO ( " ~s :~w : dc=~w handshake complete" , [inet :ntoa (Addr ), Port , DcId ]),
562562 {ok , S # state {stage = tunnel ,
563563 stage_state = undefined }}.
564564
0 commit comments