<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div><blockquote type="cite"><div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div style="font-family:arial,helvetica,sans-serif;font-size:12pt;color:#000000"><div><blockquote style="border-left-width: 2px; border-left-style: solid; border-left-color: rgb(16, 16, 255); margin-left: 5px; padding-left: 5px; color: rgb(0, 0, 0); font-weight: normal; font-style: normal; text-decoration: none; font-family: Helvetica, Arial, sans-serif; font-size: 12pt; position: static; z-index: auto; "><div>Or, can I log all rpc_call(s) calling my gen_server?</div><br><div>/Frank</div><br>_______________________________________________<br>erlang-questions mailing list<br><a href="mailto:erlang-questions@erlang.org" target="_blank">erlang-questions@erlang.org</a><br><a href="http://erlang.org/mailman/listinfo/erlang-questions" target="_blank">http://erlang.org/mailman/listinfo/erlang-questions</a><br></blockquote></div></div></div></blockquote></div></div>
_______________________________________________<br>erlang-questions mailing list<br><a href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a><br>http://erlang.org/mailman/listinfo/erlang-questions<br></blockquote></div><div><br></div><div><br></div><div>General comments about appropriateness of rpc notwithstanding….</div><div><br></div><div>Consider following statements (you may run them from the shell):</div><div><br></div><div><div><font class="Apple-style-span" face="'Courier New'">(tcap2@macbookv)225> f(REX), REX=whereis(rex). </font></div><div><font class="Apple-style-span" face="'Courier New'"><0.12.0></font></div><div><font class="Apple-style-span" face="'Courier New'">(tcap2@macbookv)226> unregister( rex ). </font></div><div><font class="Apple-style-span" face="'Courier New'">true</font></div><div><font class="Apple-style-span" face="'Courier New'"><div style="font-family: Helvetica; "><font class="Apple-style-span" face="'Courier New'">(tcap2@macbookv)227> catch register( rex, self() ). </font></div><div style="font-family: Helvetica; "><font class="Apple-style-span" face="'Courier New'">true</font></div><div><font class="Apple-style-span" face="'Courier New'"><br></font></div></font></div><div><font class="Apple-style-span" face="'Courier New'"><span class="Apple-style-span" style="font-family: Helvetica; ">Then, you could go to the remote node's shell and run, say:</span></font></div><div><font class="Apple-style-span" face="'Courier New'"><span class="Apple-style-span" style="font-family: Helvetica; "><br></span></font></div><div><font class="Apple-style-span" face="'Courier New'">(tcap3@macbookv)3> <i>rpc:call( tcap2@macbookv, erlang, now, [], 1000 ).</i></font></div><div><br></div><div><i>(NOTE 1: the caller wil timeout after one second)</i></div><div><br></div><div><font class="Apple-style-span" face="'Courier New'"><span class="Apple-style-span" style="font-family: Helvetica; ">At this point, your first node will receive a message, such that:</span></font></div><div><font class="Apple-style-span" face="'Courier New'"><span class="Apple-style-span" style="font-family: Helvetica; "><br></span></font></div><div><span class="Apple-style-span" style="font-family: 'Courier New'; ">(tcap2@macbookv)228> flush().</span></div><div><font class="Apple-style-span" face="'Courier New'">Shell got {'$gen_call',{<7155.<b>38.0</b>>,#Ref<7155.0.0.59>},</font></div><div><font class="Apple-style-span" face="'Courier New'"> {call,erlang,now,[],<7155.<b>31.0</b>>}}</font></div><div><font class="Apple-style-span" face="'Courier New'">ok</font></div></div><div><br></div><div><i>(NOTE 2: <<7155.<b>38.0</b>>> is pid() of the process that issued the call)</i></div><div><i><span class="Apple-style-span" style="font-style: normal; "><i>(NOTE 3: <<7155.<b>31.0</b>>> is pid() of the group leader)</i></span></i></div><div><br></div><div>Thus, you could exploit this in order to write your own logger, which would front <i>rex</i>:</div><div><br></div><div>Consider below for incorporation in your code:</div><div><br></div><div><br></div><div><span class="Apple-style-span" style="font-family: 'Courier New'; ">...</span></div><div><font class="Apple-style-span" face="'Courier New'">-export( [init/1, logger/0] ).</font></div><div><font class="Apple-style-span" face="'Courier New'">...</font></div><div><font class="Apple-style-span" face="'Courier New'">-record( state, {rex, logger} ).</font></div><div><font class="Apple-style-span" face="'Courier New'">...</font></div><div><font class="Apple-style-span" face="'Courier New'">init( _ )</font></div><div><font class="Apple-style-span" face="'Courier New'">-></font></div><div><font class="Apple-style-span" face="'Courier New'">...</font></div><div><span class="Apple-style-span" style="font-family: 'Courier New'; "> % ---------------</span></div><div><span class="Apple-style-span" style="font-family: 'Courier New'; "> % Redirecting REX</span></div><div><span class="Apple-style-span" style="font-family: 'Courier New'; "> % ---------------</span></div><div><span class="Apple-style-span" style="font-family: 'Courier New'; "> OldREX = whereis( REX ),</span></div><div><font class="Apple-style-span" face="'Courier New'"> unregister( rex ),</font></div><div><font class="Apple-style-span" face="'Courier New'"> register( rex, self() ),</font></div><div><font class="Apple-style-span" face="'Courier New'"> </font><span class="Apple-style-span" style="font-family: 'Courier New'; ">main_loop( #state{rex=</span><span class="Apple-style-span" style="font-family: 'Courier New'; ">OldREX, logger=spawn(?MODULE, logger, []</span><span class="Apple-style-span" style="font-family: 'Courier New'; ">} )</span></div><div><span class="Apple-style-span" style="font-family: 'Courier New'; ">.</span></div><div><font class="Apple-style-span" face="'Courier New'"><br></font></div><div><font class="Apple-style-span" face="'Courier New'">main_loop( S=#state{</font><font class="Apple-style-span" face="'Courier New'">} )</font></div><div><font class="Apple-style-span" face="'Courier New'">-></font></div><div><font class="Apple-style-span" face="'Courier New'"> NewS = receive</font></div><div><font class="Apple-style-span" face="'Courier New'"> Request </font><span class="Apple-style-span" style="font-family: 'Courier New'; ">-> f</span><span class="Apple-style-span" style="font-family: 'Courier New'; ">wd_request(</span><span class="Apple-style-span" style="font-family: 'Courier New'; ">Request</span><span class="Apple-style-span" style="font-family: 'Courier New'; ">, S)</span></div><div><font class="Apple-style-span" face="'Courier New'"> end,</font></div><div><font class="Apple-style-span" face="'Courier New'"> main_loop( NewS )<span class="Apple-tab-span" style="white-space:pre"> </span></font></div><div><font class="Apple-style-span" face="'Courier New'">;</font></div><div><font class="Apple-style-span" face="'Courier New'"><span class="Apple-style-span" style="font-family: Helvetica; "><font class="Apple-style-span" face="'Courier New'">main_loop( {shutdown, #state{rex=</font></span><span class="Apple-style-span" style="font-family: Helvetica; "><span class="Apple-style-span" style="font-family: 'Courier New'; ">OldREX, logger=LPID</span></span><span class="Apple-style-span" style="font-family: Helvetica; "><font class="Apple-style-span" face="'Courier New'">}} )</font></span></font></div><div><font class="Apple-style-span" face="'Courier New'"><span class="Apple-style-span" style="font-family: Helvetica; "><font class="Apple-style-span" face="'Courier New'">-></font></span></font></div><div><span class="Apple-style-span" style="font-family: 'Courier New'; "> % ---------------</span></div><div><font class="Apple-style-span" face="'Courier New'"> % Exit gracefully</font></div><div><font class="Apple-style-span" face="'Courier New'"> % ---------------</font></div><div><font class="Apple-style-span" face="'Courier New'"> unregister( rex ),</font></div><div><font class="Apple-style-span" face="'Courier New'"> register( rex, OldRex ),</font></div><div><font class="Apple-style-span" face="'Courier New'"> LPID ! shutdown,</font></div><div><font class="Apple-style-span" face="'Courier New'"> exit( normal )</font></div><div><font class="Apple-style-span" face="'Courier New'">.</font></div><div><font class="Apple-style-span" face="'Courier New'"><br></font></div><div><span class="Apple-style-span" style="font-family: 'Courier New'; ">f</span><span class="Apple-style-span" style="font-family: 'Courier New'; ">wd_request</span><span class="Apple-style-span" style="font-family: 'Courier New'; ">( Request=</span><span class="Apple-style-span" style="font-family: 'Courier New'; ">{'$gen_call',{CallerPID,CallerRef}, </span><span class="Apple-style-span" style="font-family: 'Courier New'; ">{call,Mod,Func,Args,_CallerGroupLeader}}</span><span class="Apple-style-span" style="font-family: 'Courier New'; ">, S=#state{rex=OldRex, logger=LPID} )</span></div><div><font class="Apple-style-span" face="'Courier New'">-></font></div><div><font class="Apple-style-span" face="'Courier New'"> OldRex ! Request, </font></div><div><font class="Apple-style-span" face="'Courier New'"> LPID ! {log, CallerPid, CallerRef, Mod, Func, Args},</font></div><div><span class="Apple-style-span" style="font-family: 'Courier New'; "> S</span></div><div><font class="Apple-style-span" face="'Courier New'">;</font></div><div><font class="Apple-style-span" face="'Courier New'">f<span class="Apple-style-span" style="font-family: 'Courier New'; ">wd_request</span><font class="Apple-style-span" face="'Courier New'">( shutdown, S ) </font><span class="Apple-style-span" style="font-family: 'Courier New'; ">-> {shutdown, S};</span></font></div><div><font class="Apple-style-span" face="'Courier New'">f<span class="Apple-style-span" style="font-family: 'Courier New'; ">wd_request</span><font class="Apple-style-span" face="'Courier New'">( _, S ) -> S.</font></font></div><div><font class="Apple-style-span" face="'Courier New'"><font class="Apple-style-span" face="'Courier New'"><br></font></font></div><div><font class="Apple-style-span" face="'Courier New'">% ------</font></div><div><font class="Apple-style-span" face="'Courier New'">% LOGGER</font></div><div><font class="Apple-style-span" face="'Courier New'">% ------</font></div><div><font class="Apple-style-span" face="'Courier New'">logger()</font></div><div><font class="Apple-style-span" face="'Courier New'">-></font></div><div><font class="Apple-style-span" face="'Courier New'"> receive</font></div><div><font class="Apple-style-span" face="'Courier New'"> {log, CallerPid, CallerRef, Mod, Func, Args}</font></div><div><font class="Apple-style-span" face="'Courier New'"> -></font></div><div><font class="Apple-style-span" face="'Courier New'"> ... <i>Do some logging stuff ...</i></font></div><div><font class="Apple-style-span" face="'Courier New'"> ;</font></div><div><font class="Apple-style-span" face="'Courier New'"> shutdown -> exit( normal );</font></div><div><font class="Apple-style-span" face="'Courier New'"> _<span class="Apple-tab-span" style="white-space:pre"> </span> -> void </font></div><div><font class="Apple-style-span" face="'Courier New'"> end,</font></div><div><font class="Apple-style-span" face="'Courier New'"> logger()</font></div><div><font class="Apple-style-span" face="'Courier New'">.</font></div><div><br></div><div>Kind regards</div><div><br></div><div>V/</div><div><br></div><div>PS</div><div>Just want to state the obvious: I did not compile this code. It could contain bugs, but it illustrates the point.</div><div><br></div><div><br></div><div><br></div></body></html>