From b8e5e0a1b915b7589195858ba97c4e87904e7390 Mon Sep 17 00:00:00 2001 From: Jared Johnson Date: Wed, 3 Dec 2014 15:50:45 -0600 Subject: [PATCH] Make content log file configurable --- plugins/content_log | 16 ++++++++++++++-- t/plugin_tests/content_log | 11 ++++++++++- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/plugins/content_log b/plugins/content_log index 9392f69..65daf59 100644 --- a/plugins/content_log +++ b/plugins/content_log @@ -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 + +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 { diff --git a/t/plugin_tests/content_log b/t/plugin_tests/content_log index 61a5e2a..63ad855 100644 --- a/t/plugin_tests/content_log +++ b/t/plugin_tests/content_log @@ -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 {