Make content log file configurable

This commit is contained in:
Jared Johnson 2014-12-03 15:50:45 -06:00
parent 5375c9818d
commit b8e5e0a1b9
2 changed files with 24 additions and 3 deletions

View File

@ -16,6 +16,16 @@ Useful for debugging other plugins or keeping an archive of things.
Used to enable and disable content logging
Default: true
=head2 content_log_file <pattern>
Path to the content log file.
This option is passed through strftime(); see
http://man7.org/linux/man-pages/man3/strftime.3.html
or the appropriate documentation for your operating system)
Default: mail/%Y%m%d
=cut
use POSIX qw:strftime:;
@ -47,9 +57,11 @@ sub data_post_handler {
}
sub content_log_file {
my ( $self ) = @_;
# as a decent default, log on a per-day-basis
my $date = strftime("%Y%m%d", localtime(time));
return "mail/$date";
my $path = $self->qp->config('content_log_file');
$path ||= 'mail/%Y%m%d';
return strftime($path, localtime(time));
}
sub content_log_enabled {

View File

@ -2,6 +2,7 @@
use strict;
use warnings;
use POSIX qw( strftime );
sub register_tests {
my ( $self ) = @_;
@ -12,7 +13,15 @@ sub register_tests {
sub test_content_log_file {
my ( $self ) = @_;
ok( $self->content_log_file, 'content_log_file() returns something' );
is( $self->content_log_file,
strftime('mail/%Y%m%d', localtime(time)),
'content_log_file() returns the right default value' );
$self->save_hook;
$self->fake_config('/path/to/%Y%m%d%H%M');
is( $self->content_log_file,
strftime('/path/to/%Y%m%d%H%M', localtime(time)),
'content_log_file config changes content_log_file() output' );
$self->restore_hook;
}
sub test_content_log_enabled {