Changeset e08487a for perl/lib


Ignore:
Timestamp:
Aug 5, 2017, 11:23:02 PM (7 years ago)
Author:
Jason Gross <jgross@mit.edu>
Children:
9410677
Parents:
4bbe53a
git-author:
Jason Gross <jgross@mit.edu> (07/12/11 12:34:46)
git-committer:
Jason Gross <jgross@mit.edu> (08/05/17 23:23:02)
Message:
Moved log generation code to perl.
Location:
perl/lib/BarnOwl
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • perl/lib/BarnOwl/Message.pm

    r0adbce1 re08487a  
    115115    }
    116116    return $s;
     117}
     118
     119=head2 log MESSAGE
     120
     121Returns the text that should be written to a file to log C<MESSAGE>.
     122
     123=cut
     124
     125sub log {
     126    my ($m) = @_;
     127    return $m->log_header . "\n\n" . $m->log_body . "\n\n";
     128}
     129
     130=head2 log_header MESSAGE
     131
     132Returns the header of the message, for logging purposes.
     133If you override L<BarnOwl::Message::log>, this method is not called.
     134
     135=cut
     136
     137sub log_header {
     138    my ($m) = @_;
     139    my $sender = $m->sender;
     140    my $recipient = $m->recipient;
     141    my $timestr = $m->time;
     142    return "From: <$sender> To: <$recipient>\n"
     143         . "Time: $timestr";
     144}
     145
     146=head2 log_body MESSAGE
     147
     148Returns the body of the message, for logging purposes.
     149If you override L<BarnOwl::Message::log>, this method is not called.
     150
     151=cut
     152
     153sub log_body {
     154    my ($m) = @_;
     155    if ($m->is_loginout) {
     156        return uc($m->login)
     157            . $m->login_type
     158            . ($m->login_extra ? ' at ' . $m->login_extra : '');
     159    } else {
     160        return $m->body;
     161    }
    117162}
    118163
  • perl/lib/BarnOwl/Message/Zephyr.pm

    r0adbce1 re08487a  
    223223}
    224224
     225# Logging
     226sub log_header {
     227    my ($m) = @_;
     228    my $class = $m->class;
     229    my $instance = $m->instance;
     230    my $opcode = $m->opcode;
     231    my $timestr = $m->time;
     232    my $host = $m->host;
     233    my $sender = $m->pretty_sender;
     234    my $zsig = $m->zsig;
     235    my $rtn = "Class: $class Instance: $instance";
     236    $rtn .= " Opcode: $opcode" unless !defined $opcode || $opcode eq '';
     237    $rtn .= "\nTime: $timestr Host: $host"
     238          . "\nFrom: $zsig <$sender>";
     239    return $rtn;
     240}
    225241
    2262421;
Note: See TracChangeset for help on using the changeset viewer.