diff options
| -rw-r--r-- | FS/FS/Log.pm | 33 | ||||
| -rw-r--r-- | FS/FS/Upgrade.pm | 3 | ||||
| -rw-r--r-- | FS/FS/log.pm | 47 | ||||
| -rw-r--r-- | httemplate/browse/log_email.html | 2 | ||||
| -rw-r--r-- | httemplate/edit/log_email.html | 4 | ||||
| -rw-r--r-- | httemplate/search/log.html | 35 | 
6 files changed, 98 insertions, 26 deletions
| diff --git a/FS/FS/Log.pm b/FS/FS/Log.pm index b11630bc9..247f8efef 100644 --- a/FS/FS/Log.pm +++ b/FS/FS/Log.pm @@ -5,13 +5,20 @@ use FS::Record qw(qsearch qsearchs);  use FS::Conf;  use FS::Log::Output;  use FS::log; -use vars qw(@STACK @LEVELS); +use vars qw(@STACK %LEVELS);  # override the stringification of @_ with something more sensible.  BEGIN { -  @LEVELS = qw(debug info notice warning error critical alert emergency); +  # subset of Log::Dispatch levels +  %LEVELS = ( +    0 => 'debug', +    1 => 'info', +    3 => 'warning', +    4 => 'error', +    5 => 'critical' +  ); -  foreach my $l (@LEVELS) { +  foreach my $l (values %LEVELS) {      my $sub = sub {        my $self = shift;        $self->log( level => $l, message => @_ ); @@ -100,4 +107,24 @@ sub DESTROY {    splice(@STACK, $self->{'index'}, 1); # delete the stack entry  } +=item levelnums + +Subroutine.  Returns ordered list of level nums. + +=cut + +sub levelnums { +  sort keys %LEVELS; +} + +=item levelmap + +Subroutine.  Returns ordered map of level num => level name. + +=cut + +sub levelmap { +  map { $_ => $LEVELS{$_} } levelnums; +} +  1; diff --git a/FS/FS/Upgrade.pm b/FS/FS/Upgrade.pm index f26c6a338..bbd1ee12b 100644 --- a/FS/FS/Upgrade.pm +++ b/FS/FS/Upgrade.pm @@ -335,6 +335,9 @@ sub upgrade_data {      #fix whitespace - before cust_main      'cust_location' => [], +    #remap log levels +    'log' => [], +      #cust_main (tokenizes cards, remove paycvv from history, locations, cust_payby, etc)      # (handles payinfo encryption/tokenization across all relevant tables)      'cust_main' => [], diff --git a/FS/FS/log.pm b/FS/FS/log.pm index 769d6fce1..75e17c847 100644 --- a/FS/FS/log.pm +++ b/FS/FS/log.pm @@ -6,6 +6,8 @@ use FS::Record qw( qsearch qsearchs dbdef );  use FS::UID qw( dbh driver_name );  use FS::log_context;  use FS::log_email; +use FS::upgrade_journal; +use Tie::IxHash;  =head1 NAME @@ -113,7 +115,7 @@ sub insert {        'msgtype'       => 'admin',        'to'            => $log_email->to_addr,        'substitutions' => { -        'loglevel'   => $FS::Log::LEVELS[$self->level], # which has hopefully been loaded... +        'loglevel'   => $FS::Log::LEVELS{$self->level}, # which has hopefully been loaded...          'logcontext' => $log_email->context, # use the one that triggered the email          'logmessage' => $self->message,        }, @@ -381,6 +383,49 @@ sub search {    };  } +sub _upgrade_data { +  my ($class, %opts) = @_; + +  return if FS::upgrade_journal->is_done('log__remap_levels'); + +  tie my %levelmap, 'Tie::IxHash',  +    2 => 1, #notice -> info +    6 => 5, #alert -> critical +    7 => 5, #emergency -> critical +  ; + +  # this method should never autocommit +  # should have been set in upgrade, but just in case... +  local $FS::UID::AutoCommit = 0; + +  # in practice, only debug/info/warning/error appear to have been used, +  #   so this probably won't do anything, but just in case +  foreach my $old (keys %levelmap) { +    # FS::log has no replace method +    my $sql = 'UPDATE log SET level=' . dbh->quote($levelmap{$old}) . ' WHERE level=' . dbh->quote($old); +    warn $sql unless $opts{'quiet'}; +    my $sth = dbh->prepare($sql) or die dbh->errstr; +    $sth->execute() or die $sth->errstr; +    $sth->finish(); +  } + +  foreach my $log_email ( +    qsearch('log_email',{ 'min_level' => 2 }), +    qsearch('log_email',{ 'min_level' => 6 }), +    qsearch('log_email',{ 'min_level' => 7 }), +  ) { +    $log_email->min_level($levelmap{$log_email->min_level}); +    my $error = $log_email->replace; +    if ($error) { +      dbh->rollback; +      die $error; +    } +  } + +  FS::upgrade_journal->set_done('log__remap_levels'); + +} +  =back  =head1 BUGS diff --git a/httemplate/browse/log_email.html b/httemplate/browse/log_email.html index 0f64dd454..007ea6f74 100644 --- a/httemplate/browse/log_email.html +++ b/httemplate/browse/log_email.html @@ -21,7 +21,7 @@                        ],       'fields'      => [ 'logemailnum',                          sub { $_[0]->context || '(all)' }, -                        sub { $FS::Log::LEVELS[$_[0]->min_level] }, +                        sub { $FS::Log::LEVELS{$_[0]->min_level} },                          'msgname',                          'to_addr',                          $actions, diff --git a/httemplate/edit/log_email.html b/httemplate/edit/log_email.html index 709a24069..19b415d4d 100644 --- a/httemplate/edit/log_email.html +++ b/httemplate/edit/log_email.html @@ -10,8 +10,8 @@                              },                              { 'field' => 'min_level',                                'type'  => 'select', -                              'options' => [ 0..7 ], -                              'labels' => { map {$_ => $FS::Log::LEVELS[$_]} 0..7 }, +                              'options' => [ &FS::Log::levelnums ], +                              'labels' => { &FS::Log::levelmap },                                'curr_value' => scalar($cgi->param('min_level')),                              },                              'to_addr', diff --git a/httemplate/search/log.html b/httemplate/search/log.html index 9a61a71e1..9c17feef5 100644 --- a/httemplate/search/log.html +++ b/httemplate/search/log.html @@ -81,16 +81,16 @@ a:visited {text-decoration: none}    <TD>Level      <& /elements/select.html,        field      => 'min_level', -      options    => [ 0..7 ], -      labels     => { map {$_ => $FS::Log::LEVELS[$_]} 0..7 }, -      curr_value => scalar($cgi->param('min_level')), +      options    => [ &FS::Log::levelnums ], +      labels     => { &FS::Log::levelmap }, +      curr_value => $cgi->param('min_level'),      &>       to      <& /elements/select.html,        field      => 'max_level', -      options    => [ 0..7 ], -      labels     => { map {$_ => $FS::Log::LEVELS[$_]} 0..7 }, -      curr_value => scalar($cgi->param('max_level')), +      options    => [ &FS::Log::levelnums ], +      labels     => { &FS::Log::levelmap }, +      curr_value => $cgi->param('max_level'),      &>    </TD>    <TD> @@ -128,7 +128,7 @@ a:visited {text-decoration: none}  <%once>  my $date_sub = sub { time2str('%Y-%m-%d %T', $_[0]->_date) }; -my $level_sub = sub { $FS::Log::LEVELS[$_[0]->level] }; +my $level_sub = sub { $FS::Log::LEVELS{$_[0]->level} };  my $context_sub = sub {    my $log = shift; @@ -191,18 +191,15 @@ my $object_link_sub = sub {    }  }; -my @colors = ( -  '404040', #debug -  '0000aa', #info -  '00aa00', #notice -  'aa0066', #warning -  '000000', #error -  'aa0000', #critical -  'ff0000', #alert -  'ff0000', #emergency +my %colors = ( +  0 => '404040', #debug, gray +  1 => '000000', #info, black +  3 => '0000aa', #warning, blue +  4 => 'aa0066', #error, purple +  5 => 'ff0000', #critical, red  ); -my $color_sub = sub { $colors[ $_[0]->level ]; }; +my $color_sub = sub { $colors{ $_[0]->level }; };  my @contexts = ('', sort FS::log_context->contexts);  </%once> @@ -212,10 +209,10 @@ die "access denied"    unless $curuser->access_right([ 'View system logs', 'Configuration' ]);  my @menubar = (); -push @menubar, qq(<A HREF="${fsurl}browse/log_email.html" STYLE="text-decoration: underline;">Configure conditions for sending email when logging</A>), +push @menubar, qq(<A HREF="${fsurl}browse/log_email.html" STYLE="text-decoration: underline;">Configure conditions for sending email when logging</A>);  $cgi->param('min_level', 0) unless defined($cgi->param('min_level')); -$cgi->param('max_level', 7) unless defined($cgi->param('max_level')); +$cgi->param('max_level', 5) unless defined($cgi->param('max_level'));  my %search = ();  $search{'date'} = [ FS::UI::Web::parse_beginning_ending($cgi) ]; | 
