Changeset c877a63


Ignore:
Timestamp:
Jan 7, 2014, 6:00:45 PM (8 years ago)
Author:
Jason Gross <jgross@mit.edu>
Children:
e7ab1d7
Parents:
db1a2f8b
git-author:
Jason Gross <jgross@mit.edu> (07/12/11 12:34:46)
git-committer:
Jason Gross <jgross@mit.edu> (01/07/14 18:00:45)
Message:
Moved log generation code to perl.
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • logging.c

    rdb1a2f8b rc877a63  
    7777}
    7878
    79 CALLER_OWN char *owl_log_zephyr(const owl_message *m)
    80 {
    81     char *tmp = NULL;
    82     GString *buffer = NULL;
    83     buffer = g_string_new("");
    84     tmp = short_zuser(owl_message_get_sender(m));
    85     g_string_append_printf(buffer, "Class: %s Instance: %s",
    86                            owl_message_get_class(m),
    87                            owl_message_get_instance(m));
    88     if (strcmp(owl_message_get_opcode(m), "")) {
    89       g_string_append_printf(buffer, " Opcode: %s",
    90                              owl_message_get_opcode(m));
    91     }
    92     g_string_append_printf(buffer, "\n");
    93     g_string_append_printf(buffer, "Time: %s Host: %s\n",
    94                            owl_message_get_timestr(m),
    95                            owl_message_get_hostname(m));
    96     g_string_append_printf(buffer, "From: %s <%s>\n\n",
    97                            owl_message_get_zsig(m), tmp);
    98     g_string_append_printf(buffer, "%s\n\n", owl_message_get_body(m));
    99     g_free(tmp);
    100     return g_string_free(buffer, FALSE);
    101 }
    102 
    103 CALLER_OWN char *owl_log_aim(const owl_message *m)
    104 {
    105     GString *buffer = NULL;
    106     buffer = g_string_new("");
    107     g_string_append_printf(buffer, "From: <%s> To: <%s>\n",
    108                            owl_message_get_sender(m), owl_message_get_recipient(m));
    109     g_string_append_printf(buffer, "Time: %s\n\n",
    110                            owl_message_get_timestr(m));
    111     if (owl_message_is_login(m)) {
    112         g_string_append_printf(buffer, "LOGIN\n\n");
    113     } else if (owl_message_is_logout(m)) {
    114         g_string_append_printf(buffer, "LOGOUT\n\n");
    115     } else {
    116         g_string_append_printf(buffer, "%s\n\n", owl_message_get_body(m));
    117     }
    118     return g_string_free(buffer, FALSE);
    119 }
    120 
    121 CALLER_OWN char *owl_log_jabber(const owl_message *m)
    122 {
    123     GString *buffer = NULL;
    124     buffer = g_string_new("");
    125     g_string_append_printf(buffer, "From: <%s> To: <%s>\n",
    126                            owl_message_get_sender(m),
    127                            owl_message_get_recipient(m));
    128     g_string_append_printf(buffer, "Time: %s\n\n",
    129                            owl_message_get_timestr(m));
    130     g_string_append_printf(buffer, "%s\n\n", owl_message_get_body(m));
    131     return g_string_free(buffer, FALSE);
    132 }
    133 
    134 CALLER_OWN char *owl_log_generic(const owl_message *m)
    135 {
    136     GString *buffer;
    137     buffer = g_string_new("");
    138     g_string_append_printf(buffer, "From: <%s> To: <%s>\n",
    139                            owl_message_get_sender(m),
    140                            owl_message_get_recipient(m));
    141     g_string_append_printf(buffer, "Time: %s\n\n",
    142                            owl_message_get_timestr(m));
    143     g_string_append_printf(buffer, "%s\n\n",
    144                            owl_message_get_body(m));
    145     return g_string_free(buffer, FALSE);
    146 }
    147 
    14879static void owl_log_error_main_thread(gpointer data)
    14980{
     
    198129
    199130void owl_log_append(const owl_message *m, const char *filename) {
    200   char *buffer = NULL;
    201   if (owl_message_is_type_zephyr(m)) {
    202     buffer = owl_log_zephyr(m);
    203   } else if (owl_message_is_type_jabber(m)) {
    204     buffer = owl_log_jabber(m);
    205   } else if (owl_message_is_type_aim(m)) {
    206     buffer = owl_log_aim(m);
    207   } else {
    208     buffer = owl_log_generic(m);
    209   }
     131  char *buffer = owl_perlconfig_message_call_method(m, "log", 0, NULL);
    210132  owl_log_enqueue_message(buffer, filename);
    211133  g_free(buffer);
  • perl/lib/BarnOwl/Message.pm

    r0adbce1 rc877a63  
    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 rc877a63  
    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.