Changeset 5093c6f for logging.c


Ignore:
Timestamp:
Aug 16, 2017, 12:53:41 PM (7 years ago)
Author:
Jason Gross <jasongross9@gmail.com>
Branches:
master
Children:
4ead7b3
Parents:
9bfab40
git-author:
Jason Gross <jgross@mit.edu> (07/12/11 16:19:57)
git-committer:
Jason Gross <jasongross9@gmail.com> (08/16/17 12:53:41)
Message:
Moved the checking of whether or not to log messages to perl
File:
1 edited

Legend:

Unmodified
Added
Removed
  • logging.c

    r9bfab40 r5093c6f  
    3030  }
    3131
    32   /* should we be logging this message? */
    33   if (!owl_log_shouldlog_message(m)) {
    34     owl_function_debugmsg("owl_log_message: not logging message");
    35     return;
    36   }
    37 
    38   owl_log_perl(m);
     32  g_free(owl_perlconfig_call_with_message("BarnOwl::Logging::log", m));
    3933
    4034  owl_function_debugmsg("owl_log_message: leaving");
    41 }
    42 
    43 /* Return 1 if we should log the given message, otherwise return 0 */
    44 int owl_log_shouldlog_message(const owl_message *m) {
    45   const owl_filter *f;
    46 
    47   /* If there's a logfilter and this message matches it, log */
    48   f=owl_global_get_filter(&g, owl_global_get_logfilter(&g));
    49   if (f && owl_filter_message_match(f, m)) return(1);
    50 
    51   /* otherwise we do things based on the logging variables */
    52 
    53   /* skip login/logout messages if appropriate */
    54   if (!owl_global_is_loglogins(&g) && owl_message_is_loginout(m)) return(0);
    55      
    56   /* check direction */
    57   if ((owl_global_get_loggingdirection(&g)==OWL_LOGGING_DIRECTION_IN) && owl_message_is_direction_out(m)) {
    58     return(0);
    59   }
    60   if ((owl_global_get_loggingdirection(&g)==OWL_LOGGING_DIRECTION_OUT) && owl_message_is_direction_in(m)) {
    61     return(0);
    62   }
    63 
    64   if (owl_message_is_type_zephyr(m)) {
    65     if (owl_message_is_personal(m) && !owl_global_is_logging(&g)) return(0);
    66     if (!owl_message_is_personal(m) && !owl_global_is_classlogging(&g)) return(0);
    67   } else {
    68     if (owl_message_is_private(m) || owl_message_is_loginout(m)) {
    69       if (!owl_global_is_logging(&g)) return(0);
    70     } else {
    71       if (!owl_global_is_classlogging(&g)) return(0);
    72     }
    73   }
    74   return(1);
    7535}
    7636
     
    302262}
    303263
    304 void owl_log_append(const owl_message *m, const char *filename) {
    305   char *buffer = owl_perlconfig_message_call_method(m, "log", 0, NULL);
    306   owl_log_enqueue_message(buffer, filename);
    307   g_free(buffer);
    308 }
    309 
    310264void owl_log_outgoing_zephyr_error(const owl_zwrite *zw, const char *text)
    311265{
    312   owl_message *m;
    313   /* create a present message so we can pass it to
    314    * owl_log_shouldlog_message(void)
    315    */
    316   m = g_slice_new(owl_message);
     266  owl_message *m = g_slice_new(owl_message);
    317267  /* recip_index = 0 because there can only be one recipient anyway */
    318268  owl_message_create_from_zwrite(m, zw, text, 0);
    319   if (!owl_log_shouldlog_message(m)) {
    320     owl_message_delete(m);
    321     return;
    322   }
    323   char *buffer = owl_perlconfig_message_call_method(m, "log_outgoing_error", 0, NULL);
    324   char *filenames_string = owl_perlconfig_call_with_message("BarnOwl::Logging::get_filenames_as_string", m);
    325   char **filenames = g_strsplit(filenames_string, " ", 0);
    326   char **filename_ptr;
    327 
    328   for (filename_ptr = filenames; *filename_ptr != NULL; filename_ptr++) {
    329     owl_log_enqueue_message(buffer, *filename_ptr);
    330   }
    331 
    332   g_free(filenames_string);
    333   g_strfreev(filenames);
     269  g_free(owl_perlconfig_call_with_message("BarnOwl::Logging::log_outgoing_error", m));
    334270  owl_message_delete(m);
    335 }
    336 
    337 void owl_log_perl(const owl_message *m)
    338 {
    339   char *filenames_string = owl_perlconfig_call_with_message("BarnOwl::Logging::get_filenames_as_string", m);
    340   char **filenames = g_strsplit(filenames_string, "\n", 0);
    341   char **filename_ptr;
    342   g_free(filenames_string);
    343 
    344   for (filename_ptr = filenames; *filename_ptr != NULL; filename_ptr++) {
    345     owl_log_append(m, *filename_ptr);
    346   }
    347 
    348   g_strfreev(filenames);
    349271}
    350272
Note: See TracChangeset for help on using the changeset viewer.