--- trunk/run.pl 2006/09/07 15:01:45 652 +++ trunk/run.pl 2006/09/11 15:59:35 671 @@ -363,6 +363,16 @@ %{ $input }, ); + my $report_fh; + if ($stats || $validate) { + my $path = "out/report/" . $database . '-' . $input->{name} . '.txt'; + open($report_fh, '>', $path) || $log->logdie("can't open $path: $!"); + + print $report_fh "Report for database '$database' input '$input->{name}' records ", + $offset || 1, "-", $limit || $input->{limit} || $maxmfn, "\n\n"; + $log->info("Generating report file $path"); + } + my @norm_array = ref($input->{normalize}) eq 'ARRAY' ? @{ $input->{normalize} } : ( $input->{normalize} ); @@ -406,11 +416,9 @@ if ($validate) { - if ( my $errors = $validate->validate_errors( $row ) ) { - my $dump_record = defined($errors->{dump}->{record}); - $log->error( "MFN $mfn\n", - $dump_record ? $input_db->dump : '', - "validation errors:\n", dump( $errors ) + if ( my $errors = $validate->validate_errors( $row, $input_db->dump ) ) { + $log->error( "MFN $mfn validation error:\n", + $validate->report_error( $errors ) ); } } @@ -465,13 +473,25 @@ $total_rows++; } - $log->info("validation errors:\n", dump( $validate->{errors} ) ) if ($validate && defined($validate->{errors})); + if ($validate) { + my $errors = $validate->report; + if ($errors) { + $log->info("validation errors:\n$errors\n" ); + print $report_fh "$errors\n" if ($report_fh); + } + } - $log->info("statistics of fields usage:\n", $input_db->stats) if ($stats); + if ($stats) { + my $s = $input_db->stats; + $log->info("statistics of fields usage:\n$s"); + print $report_fh "Statistics of fields usage:\n$s" if ($report_fh); + } # close MARC file $marc->finish if ($marc); + # close report + close($report_fh) || $log->logdie("can't close report: $!"); } }