Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

assume file path ending with slash as directory, and append it with '…

…$name.log'; prepare v0.24
  • Loading branch information...
commit bc0d7a689d7a342b174d1a6798c6aeca9372b912 1 parent cf03068
Steven Haryanto (on PC) authored
View
4 Changes
@@ -1,5 +1,9 @@
Revision history for Log-Any-App
+0.24 2010-12-17
+ - If file path ends with a /, it is assumed to be a directory and log
+ name is appended to it
+
0.23 2010-11-11
- Fix test: untaint path for FileRotate [ct]
View
2  dist.ini
@@ -1,5 +1,5 @@
name = Log-Any-App
-version = 0.23
+version = 0.24
author = Steven Haryanto <stevenharyanto@gmail.com>
license = Perl_5
copyright_holder = Steven Haryanto
View
18 lib/Log/Any/App.pm
@@ -400,6 +400,9 @@ C</var/log/$NAME.log>, where $NAME is taken from B<$0> (or
C<-name>). Otherwise the default path is ~/$NAME.log. Intermediate
directories will be made with L<File::Path>.
+If specified C<path> ends with a slash (e.g. "/my/log/"), it is assumed to be a
+directory and the final file path is directory appended with $NAME.log.
+
Default rotating behaviour is no rotate (max_size = 0).
Default level for file is the same as the global level set by
@@ -924,6 +927,7 @@ sub _parse_opt_OUTPUT {
my (%args) = @_;
my $kind = $args{kind};
my $default_sub = $args{default_sub};
+ my $postprocess = $args{postprocess};
my $spec = $args{spec};
my $arg = $args{arg};
@@ -950,6 +954,8 @@ sub _parse_opt_OUTPUT {
}
$spec->{$kind}[-1]{main_spec} = $spec;
_set_pattern($spec->{$kind}[-1], $kind);
+ $postprocess->(spec => $spec, ospec => $spec->{$kind}[-1])
+ if $postprocess;
} elsif (ref($arg) eq 'ARRAY') {
for (@$arg) {
_parse_opt_OUTPUT(%args, arg => $_);
@@ -990,6 +996,18 @@ sub _parse_opt_file {
_parse_opt_OUTPUT(
kind => 'file', default_sub => \&_default_file,
spec => $spec, arg => $arg,
+ postprocess => sub {
+ my (%args) = @_;
+ my $spec = $args{spec};
+ my $ospec = $args{ospec};
+ if ($ospec->{path} =~ m!/$!) {
+ my $p = $ospec->{path};
+ $p .= "$spec->{name}.log";
+ _debug("File path ends with /, assumed to be dir, ".
+ "final path becomes $p");
+ $ospec->{path} = $p;
+ }
+ },
);
}
View
34 t/01-basics.t
@@ -9,7 +9,7 @@ use strict;
use warnings;
use Log::Any::App -dir => 0, -file => 0, -screen => 0, -syslog => 0, -init => 0;
-use Test::More tests => 59;
+use Test::More tests => 63;
test_init(
name => 'default',
@@ -28,6 +28,10 @@ test_init(
my %vars;
+
+
+# TESTING LEVEL
+
%vars = (
loglevel => ["fatal", "fatal"],
log_level => ["error", "error"],
@@ -122,6 +126,34 @@ while (my ($k, $v) = each %vars) {
); #2
} #=4x2
+
+
+# TESTING FILE
+
+%vars = (
+ 1 => [-file => "/foo/bar"],
+ 2 => [-file => {path=>"/foo/bar"}],
+);
+while (my ($k, $v) = each %vars) {
+ test_init(
+ init_args => $v,
+ name => "file path without ending slash assumed as path ($k)",
+ file_params => {path => "/foo/bar"},
+ ); #1
+} #=2x1
+
+%vars = (
+ 1 => [-file => "/foo/bar/", -name => 'app'],
+ 2 => [-file => {path=>"/foo/bar/"}, -name => 'app'],
+);
+while (my ($k, $v) = each %vars) {
+ test_init(
+ init_args => $v,
+ name => "file path with ending slash assumed as directory ($k)",
+ file_params => {path => "/foo/bar/app.log"},
+ ); #1
+} #=2x1
+
# XXX priority/overrides (setting via env vs cmdline vs vars vs init args)
# XXX invalid level dies
# XXX syslog & dir: setting level
View
7 t/testlib.pl
@@ -1,3 +1,6 @@
+use strict;
+use warnings;
+
my @n_lower = qw(loglevel log_level);
my @n_ucfirst = qw(LogLevel Log_Level);
my @n_uc = qw(LOGLEVEL LOG_LEVEL);
@@ -6,7 +9,7 @@
my @s_lower = qw(quiet verbose debug trace);
my @s_ucfirst = map {ucfirst} @s_lower;
my @s_uc = map {uc} @s_lower;
-my @s = (@s_lowr, @s_ucfirst, @s_uc);
+my @s = (@s_lower, @s_ucfirst, @s_uc);
my @global_vars = (@n, @s);
for my $o (@outputs) { push @global_vars, $o."_".$_ for @n_lower }
@@ -88,7 +91,7 @@ sub test_init {
sub _test_params {
my ($kind, $ospec, $params, $name) = @_;
- while (my ($k, $v) = each %params) {
+ while (my ($k, $v) = each %$params) {
if (ref($v) eq 'Regexp') {
like($ospec->{$k}, $v, "$name: $kind param '$k' matches $v");
} else {
Please sign in to comment.
Something went wrong with that request. Please try again.