Changeset 5093c6f for perl/lib/BarnOwl
- Timestamp:
- Aug 16, 2017, 12:53:41 PM (7 years ago)
- 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)
- Location:
- perl/lib/BarnOwl
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
perl/lib/BarnOwl/Logging.pm
reea7bed4 r5093c6f 15 15 Modules wishing to customize how messages are logged should override the 16 16 relevant subroutines in the appropriate subclass of L<BarnOwl::Message>. 17 18 Modules wishing to log errors sending outgoing messages should call 19 L<BarnOwl::Logging::log_outgoing_error> with the message that failed 20 to be sent. 17 21 18 22 =head2 EXPORTS … … 76 80 } 77 81 78 # For ease of use in C 79 sub get_filenames_as_string { 80 my @rtn; 81 foreach my $filename (BarnOwl::Logging::get_filenames(@_)) { 82 $filename =~ s/\n/_/g; 83 push @rtn, $filename; 82 =head2 should_log_message MESSAGE 83 84 Determines whether or not the passed message should be logged. 85 86 To customize the behavior of this method, override 87 L<BarnOwl::Message::should_log>. 88 89 =cut 90 91 sub should_log_message { 92 my ($m) = @_; 93 # If there's a logfilter and this message matches it, log. 94 # pass quiet=1, because we don't care if the filter doesn't exist 95 return 1 if BarnOwl::message_matches_filter($m, BarnOwl::getvar('logfilter'), 1); 96 # otherwise we do things based on the logging variables 97 # skip login/logout messages if appropriate 98 return 0 if $m->is_loginout && BarnOwl::getvar('loglogins') eq 'off'; 99 # check direction 100 return 0 if $m->is_outgoing && BarnOwl::getvar('loggingdirection') eq 'in'; 101 return 0 if $m->is_incoming && BarnOwl::getvar('loggingdirection') eq 'out'; 102 return $m->should_log; 103 } 104 105 =head2 log MESSAGE 106 107 Call this method to (potentially) log a message. 108 109 To customize the behavior of this method for your messages, override 110 L<BarnOwl::Message::log>, L<BarnOwl::Message::should_log>, 111 L<BarnOwl::Message::log_base_path>, and/or 112 L<BarnOwl::Message::log_filenames>. 113 114 =cut 115 116 sub log { 117 my ($m) = @_; 118 return unless BarnOwl::Logging::should_log_message($m); 119 my $log_text = $m->log; 120 foreach my $filename (BarnOwl::Logging::get_filenames($m)) { 121 BarnOwl::Logging::enqueue_text($log_text, $filename); 84 122 } 85 return join("\n", @rtn); 123 } 124 125 =head2 log_outgoing_error MESSAGE 126 127 Call this method to (potentially) log an error in sending an 128 outgoing message. Errors get logged to the same file(s) as 129 successful messages. 130 131 To customize the behavior of this method for your messages, override 132 L<BarnOwl::Message::log_outgoing_error>, 133 L<BarnOwl::Message::should_log>, 134 L<BarnOwl::Message::log_base_path>, and/or 135 L<BarnOwl::Message::log_filenames>. 136 137 =cut 138 139 sub log_outgoing_error { 140 my ($m) = @_; 141 return unless BarnOwl::Logging::should_log_message($m); 142 my $log_text = $m->log_outgoing_error; 143 foreach my $filename (BarnOwl::Logging::get_filenames($m)) { 144 BarnOwl::Logging::enqueue_text($log_text, $filename); 145 } 86 146 } 87 147 -
perl/lib/BarnOwl/Message.pm
r9bfab40 r5093c6f 225 225 chomp $body; 226 226 return "ERROR (BarnOwl): $recipient\n$body\n\n"; 227 } 228 229 =head2 should_log MESSAGE 230 231 Returns true if we should log C<MESSAGE>. This does not override 232 user settings; if the BarnOwl variable C<loggingdirection> is in, 233 and C<MESSAGE> is outgoing and does not match the C<logfilter>, it 234 will not get logged regardless of what this method returns. 235 236 Note that this method I<does> override the BarnOwl C<logging> 237 variable; if a derived class overrides this method and does not 238 provide an alternative BarnOwl variable (such as C<classlogging>), 239 the overriding method should check the BarnOwl C<logging> variable. 240 241 Defaults to returning the value of the BarnOwl variable C<logging>. 242 243 =cut 244 245 sub should_log { 246 return BarnOwl::getvar('logging') eq 'on'; 227 247 } 228 248 -
perl/lib/BarnOwl/Message/Zephyr.pm
reea7bed4 r5093c6f 281 281 } 282 282 283 sub should_log { 284 my ($m) = @_; 285 if ($m->log_to_class_file) { 286 return BarnOwl::getvar('classlogging') eq 'on'; 287 } else { 288 return BarnOwl::getvar('logging') eq 'on'; 289 } 290 } 291 283 292 1;
Note: See TracChangeset
for help on using the changeset viewer.