Changeset 6e764aa for logging.c


Ignore:
Timestamp:
Jan 7, 2014, 6:02:20 PM (8 years ago)
Author:
Jason Gross <jgross@mit.edu>
Children:
bf61c61
Parents:
f511c1e
git-author:
Jason Gross <jgross@mit.edu> (07/12/11 16:19:57)
git-committer:
Jason Gross <jgross@mit.edu> (01/07/14 18:02:20)
Message:
Moved the checking of whether or not to log messages to perl
File:
1 edited

Legend:

Unmodified
Added
Removed
  • logging.c

    rf511c1e r6e764aa  
    2424  }
    2525
    26   /* should we be logging this message? */
    27   if (!owl_log_shouldlog_message(m)) {
    28     owl_function_debugmsg("owl_log_message: not logging message");
    29     return;
    30   }
    31 
    32   owl_log_perl(m);
     26  g_free(owl_perlconfig_call_with_message("BarnOwl::Logging::log", m));
    3327
    3428  owl_function_debugmsg("owl_log_message: leaving");
    35 }
    36 
    37 /* Return 1 if we should log the given message, otherwise return 0 */
    38 int owl_log_shouldlog_message(const owl_message *m) {
    39   const owl_filter *f;
    40 
    41   /* If there's a logfilter and this message matches it, log */
    42   f=owl_global_get_filter(&g, owl_global_get_logfilter(&g));
    43   if (f && owl_filter_message_match(f, m)) return(1);
    44 
    45   /* otherwise we do things based on the logging variables */
    46 
    47   /* skip login/logout messages if appropriate */
    48   if (!owl_global_is_loglogins(&g) && owl_message_is_loginout(m)) return(0);
    49      
    50   /* check direction */
    51   if ((owl_global_get_loggingdirection(&g)==OWL_LOGGING_DIRECTION_IN) && owl_message_is_direction_out(m)) {
    52     return(0);
    53   }
    54   if ((owl_global_get_loggingdirection(&g)==OWL_LOGGING_DIRECTION_OUT) && owl_message_is_direction_in(m)) {
    55     return(0);
    56   }
    57 
    58   if (owl_message_is_type_zephyr(m)) {
    59     if (owl_message_is_personal(m) && !owl_global_is_logging(&g)) return(0);
    60     if (!owl_message_is_personal(m) && !owl_global_is_classlogging(&g)) return(0);
    61   } else {
    62     if (owl_message_is_private(m) || owl_message_is_loginout(m)) {
    63       if (!owl_global_is_logging(&g)) return(0);
    64     } else {
    65       if (!owl_global_is_classlogging(&g)) return(0);
    66     }
    67   }
    68   return(1);
    6929}
    7030
     
    12080}
    12181
    122 void owl_log_append(const owl_message *m, const char *filename) {
    123   char *buffer = owl_perlconfig_message_call_method(m, "log", 0, NULL);
    124   owl_log_enqueue_message(buffer, filename);
    125   g_free(buffer);
    126 }
    127 
    12882void owl_log_outgoing_zephyr_error(const owl_zwrite *zw, const char *text)
    12983{
    130   owl_message *m;
    131   /* create a present message so we can pass it to
    132    * owl_log_shouldlog_message(void)
    133    */
    134   m = g_slice_new(owl_message);
     84  owl_message *m = g_slice_new(owl_message);
    13585  /* recip_index = 0 because there can only be one recipient anyway */
    13686  owl_message_create_from_zwrite(m, zw, text, 0);
    137   if (!owl_log_shouldlog_message(m)) {
    138     owl_message_delete(m);
    139     return;
    140   }
    141   char *buffer = owl_perlconfig_message_call_method(m, "log_outgoing_error", 0, NULL);
    142   char *filenames_string = owl_perlconfig_call_with_message("BarnOwl::Logging::get_filenames_as_string", m);
    143   char **filenames = g_strsplit(filenames_string, " ", 0);
    144   char **filename_ptr;
    145 
    146   for (filename_ptr = filenames; *filename_ptr != NULL; filename_ptr++) {
    147     owl_log_enqueue_message(buffer, *filename_ptr);
    148   }
    149 
    150   g_free(filenames_string);
    151   g_strfreev(filenames);
     87  g_free(owl_perlconfig_call_with_message("BarnOwl::Logging::log_outgoing_error", m));
    15288  owl_message_delete(m);
    153 }
    154 
    155 void owl_log_perl(const owl_message *m)
    156 {
    157   char *filenames_string = owl_perlconfig_call_with_message("BarnOwl::Logging::get_filenames_as_string", m);
    158   char **filenames = g_strsplit(filenames_string, "\n", 0);
    159   char **filename_ptr;
    160   g_free(filenames_string);
    161 
    162   for (filename_ptr = filenames; *filename_ptr != NULL; filename_ptr++) {
    163     owl_log_append(m, *filename_ptr);
    164   }
    165 
    166   g_strfreev(filenames);
    16789}
    16890
Note: See TracChangeset for help on using the changeset viewer.