source: perl/lib/BarnOwl/DeferredLogging.pm @ 4bbe53a

Last change on this file since 4bbe53a was 4bbe53a, checked in by Jason Gross <jasongross9@gmail.com>, 7 years ago
Add a comment for documentation As per https://github.com/barnowl/barnowl/pull/109#discussion_r131532750
  • Property mode set to 100644
File size: 1.9 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    # N.B. We use new_variable_full rather than new_variable_int so
35    # that we can set a timer to flush logs when this value is
36    # changed.
37    BarnOwl::new_variable_full('flush-logs-interval',
38        {
39            default        => 60,
40            summary        => 'how often should logs be flushed, in minutes',
41            description    => "If this is set to a positive value n, deferred logs \n"
42                            . "are flushed every n minutes.  If set to a negative or \n"
43                            . "zero values, deferred logs are only flushed when the \n"
44                            . "command :flush-logs is used.",
45            get_tostring   => sub { "$flush_logs_interval" },
46            set_fromstring => sub {
47                die "Expected integer" unless $_[0] =~ /^-?[0-9]+$/;
48                $flush_logs_interval = $_[0];
49                $flush_logs_timer->stop if defined $flush_logs_timer;
50                undef $flush_logs_timer;
51                if ($flush_logs_interval > 0) {
52                    $flush_logs_timer = BarnOwl::Timer->new({
53                            name     => 'flush-logs interval timer',
54                            interval => 60 * $flush_logs_interval,
55                            cb       => sub { BarnOwl::command("flush-logs", "-q"); }
56                        });
57                }
58            },
59            validsettings => "<int>",
60            takes_on_off => 0,
61        });
62}
63
641;
Note: See TracBrowser for help on using the repository browser.