ejabberd - Comments for "[shameless plug] logging to maildir (gtalk-like)" https://www.ejabberd.im/node/4748 en Ok, then continue improving https://www.ejabberd.im/node/4748#comment-57510 <p>Ok, then continue improving your patch, if it works correctly.</p> Sat, 18 Jun 2011 21:09:01 +0000 mfoss comment 57510 at https://www.ejabberd.im Thank you. Unfortunately, I https://www.ejabberd.im/node/4748#comment-57502 <p>Thank you. </p> <p>Unfortunately, I am well aware that it was poorly written code. :)</p> <p>The reason that I had the entire main if statement duplicated with Local* variables was that when both users were on the same server, they both needed the logs -- first user would get it from a conditional execution (if from = to) and the second one would be treated like every other case.</p> <p>I'm sure it was the wrong _way_ to do it (erlang was very rude to me when I had variables local to if statements ;) but I believe that there are two separate cases that need taking under account -- local+local and local+remote (remote+local being == the latter).</p> <p>If it was a case of two different servers, only the local one required the logs.</p> <p>With your patch, I realised, that in case of local+remote, every line is logged twice. The local+local logging works fine.</p> <p>I believe that if I enclose the first logger (the one with Local* variables) in:</p> <div class="codeblock"><code>if <br /> From#jid.lserver == To#jid.lserver -&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; the whole Local...;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; From#jid.lserver /= To#jid.lserver -&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ok<br />end,</code></div> <p>then the logging is only done once for both local+local and local+remote scenarios.</p> <p>What do you think?</p> <p>I have also modified the components of the MD5 hash to:</p> <div class="codeblock"><code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; FromPart = From#jid.luser++&quot;@&quot;++From#jid.lserver++&quot;/&quot;++From#jid.resource,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ToPart = To#jid.luser++&quot;@&quot;++To#jid.lserver++&quot;/&quot;++To#jid.resource,</code></div> <p>so different resources log to different files.</p> <p>There is one side-effect to that, the first line of user1 -&gt; user2 will be logged to one file and then the continuation of the conversation starting with the first user2 -&gt; user1 message will be logged to another. I would argue that this isn't a major flaw as my aim is to have 'searchable' logs from within the email client. The premise is still there.</p> <p>I have tested a new patch (still logging to username, not username@host, sorry) and have published it on my webpage.</p> <p>Edit:</p> <p>There are occasional errors in the ejabberd log:</p> <div class="codeblock"><code>=ERROR REPORT==== 2011-06-15 14:50:46 ===<br />E(&lt;0.364.0&gt;:ejabberd_hooks:294) : {if_clause,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [{mod_log_chat,write_packet,5},<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {ejabberd_hooks,run1,3},<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {ejabberd_c2s,session_established2,2},<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {p1_fsm,handle_msg,10},<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {proc_lib,init_p_do_apply,3}]}<br />running hook: {user_send_packet,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [{jid,&quot;localuser1&quot;,&quot;localdomain1.uk&quot;,&quot;38947283631308141624863638&quot;,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &quot;localuser1&quot;,&quot;localdomain1.uk&quot;,&quot;38947283631308141624863638&quot;},<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {jid,&quot;remoteuser1&quot;,&quot;remotedomain1.com&quot;,[],&quot;remoteuser1&quot;,&quot;remotedomain1.com&quot;,[]},<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {xmlelement,&quot;message&quot;,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [{&quot;type&quot;,&quot;chat&quot;},<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {&quot;id&quot;,&quot;purplef8e5158c&quot;},<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {&quot;to&quot;,&quot;remoteuser1@remotedomain1.com&quot;}],<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [{xmlelement,&quot;active&quot;,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [{&quot;xmlns&quot;,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &quot;http://jabber.org/protocol/chatstates&quot;}],<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; []},<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {xmlelement,&quot;body&quot;,[],<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [{xmlcdata,&lt;&lt;&quot;test message.&quot;&gt;&gt;}]}]}]}</code></div> <p>When that error message occurs, the message isn't logged. That error occurs with your patch (with my local=remote if statement) but doesn't with my patch (that now has the md5 code incorporated).</p> Wed, 15 Jun 2011 14:11:02 +0000 donotwantacct comment 57502 at https://www.ejabberd.im Modified patch with some https://www.ejabberd.im/node/4748#comment-57457 <p>Modified patch with some changes that you may want:</p> <p>* Use Direction of the stanza delivery to decide who to consider Local and Remote<br /> * Use an Erlang md5 function<br /> * Remove an IF bifurcation that seems useless (later I realized there's many more useless code)<br /> * In the filename, identify as JID, not as username<br /> * Fix indentation using Emacs</p> <p><noindex><a href="http://tkabber.jabber.ru/files/badlop/mod_log_chat_maildir-md5.patch" title="http://tkabber.jabber.ru/files/badlop/mod_log_chat_maildir-md5.patch" rel="nofollow" >http://tkabber.jabber.ru/files/badlop/mod_log_chat_maildir-md5.patch</a></noindex></p> Sat, 11 Jun 2011 10:30:31 +0000 mfoss comment 57457 at https://www.ejabberd.im