1 | use strict; |
---|
2 | use warnings; |
---|
3 | |
---|
4 | package BarnOwl::DeferredLogging; |
---|
5 | |
---|
6 | =head1 BarnOwl::DeferredLogging |
---|
7 | |
---|
8 | =head1 DESCRIPTION |
---|
9 | |
---|
10 | C<BarnOwl::DeferredLogging> adds variables relevant to deferred logging. |
---|
11 | |
---|
12 | =head2 USAGE |
---|
13 | |
---|
14 | Not Applicable. |
---|
15 | |
---|
16 | =head2 EXPORTS |
---|
17 | |
---|
18 | None by default. |
---|
19 | |
---|
20 | =cut |
---|
21 | |
---|
22 | use BarnOwl::Timer; |
---|
23 | use Exporter; |
---|
24 | |
---|
25 | our @EXPORT_OK = qw(); |
---|
26 | |
---|
27 | our %EXPORT_TAGS = (all => [@EXPORT_OK]); |
---|
28 | |
---|
29 | $BarnOwl::Hooks::startup->add("BarnOwl::DeferredLogging::_register_variables"); |
---|
30 | |
---|
31 | sub _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 | |
---|
64 | 1; |
---|