Love me or hate me for it, I'm a mac user. So of course, I use Adium as my chat client. I think the log searching is horrible in the app, so I wrote my own in perl. the first script sits in my local cgi-bin dir, and I made a firefox keyword so I can just type 'adm cheese' to search my logs for "cheese" and it will give me a nice pretty display of the search results. I use prep from CPAN to make things a little more portable than if I used system's grep command instead.

adiumLog.pl, the main cgi:

#!/usr/bin/perl $|++; use strict; use CGI; my $username = 'josh'; my $logpath = "/Users/$username/Library/Application Support/Adium 2.0/ +Users/Default/Logs/"; my $query = new CGI; print $query->header; my $keyword = $query->param('keyword'); print <<__HTML__; <style type='text/css'> li { color: #666666; } .date, .time { color: blue; } .from { color: green; } .to { color: red; } .msg { color: black; } .dump { color: orange; } a,a:visited,a:active { color:#345678; } </style> <script language='javascript'> function toggle(id) { var ele = document.getElementById(id); if (ele.style.display=='none') { ele.style.display='inline'; } else { ele.style.display='none'; } } </script> <form method='post'> Search Keyword(s): <input type='text' name='keyword' value='$keyword'/ +> <br> <input type='submit' name='submit' value='submit'> </form> <hr> __HTML__ if ($keyword) { my $pwd = `pwd`; chomp $pwd; my $cmd = "/usr/local/bin/perl $pwd/adiumLog_parser.pl \"$logp +ath\" \"$keyword\""; print `$cmd`; } print "<br>done.<br>";

adiumLog_parser.pl, the search utility. My first version was a cmdline-only search utility, so that's why it loops over a pipe...originally it took in output from `grep` on STDIN.

#!/usr/bin/perl $|++; use strict; my $logpath = $ARGV[0]; my $keyword = $ARGV[1]; $logpath =~ s/\ /\\ /g; my $cmd = "perl ./prep.pl -r \"$keyword\" $logpath*"; open IN, "$cmd|"; my %msgs; my $lines; while (<IN>) { my ($file,$prot,$me,$user,$y,$m,$d,$t,$from,$msg) = $_ =~ /($l +ogpath(.+?)\.(.+?)\/(.+?)\/.+?\((\d{4})\|(\d{2})\|(\d{2})\)\.adiumLog +):\((\d\d:\d\d:\d\d)\)\ (.+?):(.+)$/; $msgs{$y}{$m}{$d}{$t}{$prot}{$me}{$user}{to} = $me eq $from ? +$user : $me; $msgs{$y}{$m}{$d}{$t}{$prot}{$me}{$user}{from} = $me eq $from +? $me : $user; $msgs{$y}{$m}{$d}{$t}{$prot}{$me}{$user}{msg} = $msg; $msgs{$y}{$m}{$d}{$t}{$prot}{$me}{$user}{file} = $file; } close IN; $/=undef; print "<ul>"; my %seen; foreach my $y (sort keys %msgs) { my $year = $msgs{$y}; foreach my $m (sort keys %$year) { my $month = $$year{$m}; foreach my $d (sort keys %$month) { my $day = $$month{$d}; foreach my $t (sort keys %$day) { my $time = $$day{$t}; foreach my $prot (sort keys %$time) { my $proto = $$time{$prot}; foreach my $me (sort keys %$proto) { my $mee = $$proto{$me}; foreach my $user (sort keys %$mee) { my $userr = $$mee{$user}; next if $seen{$$userr{file}};$seen{$$userr{file}}=1; next unless length $$userr{from}; open F, $$userr{file}; my $dump = <F>; close F; $dump =~ s/$keyword/<span class='msg'>$keyword<\/span> +/g; $dump =~ s/\n/<br>/gsm; print <<__MSG__; <li><span class='date'>$y-$m-$d</span> <span class='time'>$t</span> From <span class='from'>$$userr{from}</span> To <span class='to'>$$userr{to}</span><br> <a onclick='toggle("$$userr{file}");return false;'>sho +w log</a><br> <span class='msg'>$$userr{msg}</span> <br> <div class='dump' id="$$userr{file}" style='display:no +ne'>$dump</div> <br> </li> __MSG__ } } } } } } } print "</ul>";

In reply to Search Adium 2.0 Logs by bageler

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.