source: perl/lib/BarnOwl/DeferredLogging.pm @ 4772817

Last change on this file since 4772817 was 4772817, checked in by Jason Gross <jgross@mit.edu>, 8 years ago
Add a variable to auto-flush logs every n minutes
  • Property mode set to 100644
File size: 1.8 KB
Line 
1use strict;
2use warnings;
3
4package BarnOwl::DeferredLogging;
5
6=head1 BarnOwl::DeferredLogging
7
8=head1 DESCRIPTION
9
10C<BarnOwl::DeferredLogging> adds variables relevant to deferred logging.
11
12=head2 USAGE
13
14Not Applicable.
15
16=head2 EXPORTS
17
18None by default.
19
20=cut
21
22use BarnOwl::Timer;
23use Exporter;
24
25our @EXPORT_OK = qw();
26
27our %EXPORT_TAGS = (all => [@EXPORT_OK]);
28
29$BarnOwl::Hooks::startup->add("BarnOwl::DeferredLogging::_register_variables");
30
31sub _register_variables {
32    my $flush_logs_interval = -1;
33    my $flush_logs_timer;
34    BarnOwl::new_variable_full('flush-logs-interval',
35        {
36            default        => -1,
37            summary        => 'how often should logs be flushed, in minutes',
38            description    => "If this is set to a positive value n, deferred logs \n"
39                            . "are flushed every n minutes.  If set to a negative or \n"
40                            . "zero values, deferred logs are only flushed when the \n"
41                            . "command :flush-logs is used.",
42            get_tostring   => sub { "$flush_logs_interval" },
43            set_fromstring => sub {
44                die "Expected integer" unless $_[0] =~ /^-?[0-9]+$/;
45                $flush_logs_interval = 0 + $_[0];
46                $flush_logs_timer->stop if defined $flush_logs_timer;
47                undef $flush_logs_timer;
48                if ($flush_logs_interval > 0) {
49                    $flush_logs_timer = BarnOwl::Timer->new({
50                            name     => 'flush-logs interval timer',
51                            interval => 60 * $flush_logs_interval,
52                            cb       => sub { BarnOwl::command("flush-logs"); }
53                        });
54                }
55            },
56            validsettings => "<int>",
57            takes_on_off => 0,
58        });
59}
60
611;
Note: See TracBrowser for help on using the repository browser.