Aaron Straup Cope wrote:
> Your wish is my command. Accepts a string or an array ref. It's on its
> way to the CPAN :-)
Well, cool! If nobody objects to these changes to Config I'll check them
and and Log::Dispatch::Jabber will be good to go. I have an example
config file in /eg/, but didn't write a unit test.
===================================================================
RCS file: /cvsroot/log4perl/Log-Log4perl/lib/Log/Log4perl/Config.pm,v
retrieving revision 1.25
diff -u -r1.25 Config.pm
--- modules/Config.pm 30 Sep 2002 08:21:47 -0000 1.25
+++ modules/Config.pm 2 Oct 2002 00:13:50 -0000
@@ -169,11 +169,40 @@
$_ ne "value"
} keys %{$data->{appender}->{$appname}};
+ my %param = ();
+ foreach my $pname (@params){
+ #this could be simple value like
+ #{appender}{myAppender}{file}{value} => 'log.txt'
+ #or a structure like
+ #{appender}{myAppender}{login} =>
+ # { name => {value => 'bob'},
+ # pwd => {value => 'xxx'},
+ # }
+ #in the latter case we send a hashref to the appender
+ if (exists $data->{appender}{$appname}
+ {$pname}{value} ) {
+ $param{$pname} = $data->{appender}{$appname}
+ {$pname}{value};
+ }else{
+ $param{$pname} = {map {$_ => $data->{appender}
+ {$appname}
+ {$pname}
+ {$_}
+ {value}}
+ keys %{$data->{appender}
+ {$appname}
+ {$pname}}
+ };
+ }
+
+ }
+
$appender = Log::Log4perl::Appender->new(
$appenderclass,
name => $appname,
- map { $_ => $data->{appender}->{$appname}->{$_}->{value}
- } @params,
+ %param,
+ #map { $_ => $data->{appender}->{$appname}->{$_}->{value}
+ # } @params,
);
add_layout_by_name($data, $appender, $appname);
@@ -322,12 +351,32 @@
if(my($key, $val) = /(\S+?)\s*=\s*(.*)/) {
$val =~ s/\s+$//;
$key = unlog4j($key);
+ my $how_deep = 0;
my $ptr = $data;
for my $part (split /\.|::/, $key) {
$ptr->{$part} = {} unless exists $ptr->{$part};
$ptr = $ptr->{$part};
+ ++$how_deep;
+ }
+
+ #here's where we deal with turning multiple values like this:
+ # log4j.appender.jabbender.to = him@a.jabber.server
+ # log4j.appender.jabbender.to = her@a.jabber.server
+ #into an arrayref like this:
+ #to => { value =>
+ # ["him\@a.jabber.server", "her\@a.jabber.server"] },
+ if (exists $ptr->{value} && $how_deep > 2) {
+ if (ref ($ptr->{value}) ne 'ARRAY') {
+ my $temp = $ptr->{value};
+ $ptr->{value} = [];
+ push (@{$ptr->{value}}, $temp);
+ }
+ print ref $ptr->{value},"\n";
+ push (@{$ptr->{value}}, $val);
+ }else{
+ $ptr->{value} = $val;
}
- $ptr->{value} = $val;
+
}
}
Aaron Straup Cope wrote:
> Your wish is my command. Accepts a string or an array ref. It's on its
> way to the CPAN :-)
>
> http://perl.aaronland.info/log-dispatch/jabber/Log-Dispatch-Jabber-0.21.tar.gz
>
> <quote>
> to make the required nested hash, which we could do, but we should ask
> him to accept a string like this instead of an array ref
>
> to=>'someone@a.jabber.server'
>
> if there's only one of them. We could make an array ref if there's
> multiple things, but I don't see an easy way to trigger it if there's
> only one, and it sounds easier to ask him to change his dispatcher. So
> this could make an arrayref:
>
> log4j.appender.jabbender.to = someone@a.jabber.server
> log4j.appender.jabbender.to = someoneelse@an...
> </quote>
>
--
Happy Trails . . .
Kevin M. Goess
(and Anne and Frank)
904 Carmel Ave.
Albany, CA 94706
(510) 525-5217
|