Changeset dce72c1


Ignore:
Timestamp:
Aug 16, 2017, 12:53:41 PM (7 years ago)
Author:
Jason Gross <jasongross9@gmail.com>
Branches:
master
Children:
15b87cc
Parents:
9a34040
git-author:
Jason Gross <jgross@mit.edu> (02/16/13 23:46:21)
git-committer:
Jason Gross <jasongross9@gmail.com> (08/16/17 12:53:41)
Message:
Log to subfolders of a base path

A different subfolder for each protocol.
Location:
perl/lib/BarnOwl
Files:
3 edited

Legend:

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

    r03fbf66 rdce72c1  
    8989                           . "is selected both incoming and outgoing messages are\n"
    9090                           . "logged."
     91        });
     92
     93    BarnOwl::new_variable_string('logbasepath',
     94        {
     95            default       => '~/zlog',
     96            validsettings => '<path>',
     97            summary       => 'path for logging non-zephyr messages',
     98            description   => "Specifies a directory which must exist.\n"
     99                           . "Each non-zephyr protocol gets its own subdirectory in\n"
     100                           . "logbasepath, and messages get logged there."
    91101        });
    92102
     
    141151This method calls C<log_filenames> on C<MESSAGE> to determine the list
    142152of filenames to which C<MESSAGE> gets logged.  All filenames are
    143 relative to C<MESSAGE->log_base_path>.  If C<MESSAGE->log_to_all_file>
     153relative to C<MESSAGE->log_path>.  If C<MESSAGE->log_to_all_file>
    144154returns true, then the filename C<"all"> is appended to the list of
    145155filenames.
     
    153163    my @filenames = $m->log_filenames;
    154164    push @filenames, 'all' if $m->log_to_all_file;
    155     return map { sanitize_filename($m->log_base_path, $_) } @filenames;
     165    return map { sanitize_filename($m->log_path, $_) } @filenames;
    156166}
    157167
  • perl/lib/BarnOwl/Message.pm

    r5093c6f rdce72c1  
    33
    44package BarnOwl::Message;
     5
     6use File::Spec;
    57
    68use BarnOwl::Message::Admin;
     
    165167
    166168Returns a list of filenames to which this message should be logged.
    167 The filenames should be relative to the path returned by
    168 C<log_base_path>.  See L<BarnOwl::Logging::get_filenames> for the
    169 specification of valid filenames, and for what happens if this
    170 method returns an invalid filename.
     169The filenames should be relative to the path returned by C<log_path>.
     170See L<BarnOwl::Logging::get_filenames> for the specification of valid
     171filenames, and for what happens if this method returns an invalid
     172filename.
    171173
    172174=cut
     
    174176sub log_filenames {
    175177    my ($m) = @_;
    176     my $filename = lc($m->type);
    177     $filename = "unknown" if !defined $filename || $filename eq '';
    178     if ($m->is_incoming && $m->pretty_sender) {
    179         $filename .= ":" . $m->pretty_sender;
    180     } elsif ($m->is_outgoing && $m->pretty_recipient) {
    181         $filename .= ":" . $m->pretty_recipient;
    182     }
     178    my $filename;
     179    if ($m->is_incoming) {
     180        $filename = $m->pretty_sender;
     181    } elsif ($m->is_outgoing) {
     182        $filename = $m->pretty_recipient;
     183    }
     184    $filename = "unknown" if !defined($filename) || $filename eq '';
    183185    return ($filename);
    184186}
     
    199201}
    200202
     203=head2 log_path MESSAGE
     204
     205Returns the folder in which all messages of this class get logged.
     206
     207Defaults to C<log_base_path>/C<log_subfolder>.
     208
     209=cut
     210
     211sub log_path {
     212    my ($m) = @_;
     213    return File::Spec->catfile($m->log_base_path, $m->log_subfolder);
     214}
     215
    201216=head2 log_base_path MESSAGE
    202217
    203 Returns the base path for logging, the folder in which all messages
    204 of this class get logged.
    205 
    206 Defaults to the BarnOwl variable C<logpath>.
     218Returns the base path for logging.  See C<log_path> for more information.
     219
     220Defaults to the BarnOwl variable C<logbasepath>.
    207221
    208222=cut
    209223
    210224sub log_base_path {
    211     return BarnOwl::getvar('logpath');
     225    return BarnOwl::getvar('logbasepath');
     226}
     227
     228=head2 log_subfolder MESSAGE
     229
     230Returns the subfolder of C<log_base_path> to log messages in.
     231
     232Defaults to C<lc($m->type)>.
     233
     234=cut
     235
     236sub log_subfolder {
     237    return lc(shift->type);
    212238}
    213239
  • perl/lib/BarnOwl/Message/Zephyr.pm

    r3374de9 rdce72c1  
    274274}
    275275
    276 sub log_base_path {
     276sub log_path {
    277277    my ($m) = @_;
    278278    if ($m->log_to_class_file) {
Note: See TracChangeset for help on using the changeset viewer.