| Line 437... |
Line 437... |
| 437 |
# This is a YAML file containing serialized contents of
|
437 |
# This is a YAML file containing serialized contents of
|
| 438 |
# Parameters:
|
438 |
# Parameters:
|
| 439 |
# $$fileName - name of file to look for (reference)
|
439 |
# $$fileName - name of file to look for (reference)
|
| 440 |
# @searchPath - array of paths to find $filename
|
440 |
# @searchPath - array of paths to find $filename
|
| 441 |
#
|
441 |
#
|
| - |
|
442 |
# Returns:
|
| - |
|
443 |
# Array reference containing lines from the file
|
| - |
|
444 |
#
|
| 442 |
#######################################################
|
445 |
#######################################################
|
| 443 |
|
446 |
|
| 444 |
sub loadConfigurationFile {
|
447 |
sub loadConfigurationFile {
|
| 445 |
my ( $fileName, @searchPath ) = @_;
|
448 |
my ( $fileName, $searchPath ) = @_;
|
| - |
|
449 |
# set defaults if not provided
|
| 446 |
$$fileName = $configurationFile unless $$fileName;
|
450 |
$fileName //= $configurationFile;
|
| 447 |
@searchPath = @confFileSearchPath unless @searchPath;
|
451 |
$searchPath //= \@confFileSearchPath;
|
| - |
|
452 |
# check if path provided in file name
|
| - |
|
453 |
if ( $fileName =~ m|(.*)/([^/]+)| ) {
|
| - |
|
454 |
$searchPath = [$1];
|
| - |
|
455 |
$fileName = $2;
|
| - |
|
456 |
}
|
| 448 |
#&logIt( '', 2, "Looking for config file $$fileName in " . join( ', ', @searchPath ) );
|
457 |
#&logIt( '', 2, "Looking for config file $fileName in " . join( ', ', @searchPath ) );
|
| 449 |
my $confFile;
|
458 |
# look for the configuration file in the search paths
|
| 450 |
if ( $confFile = &findFile( $$fileName, \@searchPath ) ) {
|
459 |
if ( my $confFile = &findFile( $fileName, $searchPath ) ) {
|
| 451 |
#&logIt( '', 3, "Opening configuration from $confFile" );
|
460 |
# Read file into array of lines
|
| 452 |
my $yaml = YAML::Tiny->read( $confFile );
|
461 |
open(my $fh, '<', $confFile) or die "Cannot open $confFile: $!\n";
|
| 453 |
#&logIt( '', 4, "Configuration file contents\n$yaml" );
|
462 |
my @lines = <$fh>;
|
| 454 |
$$fileName = $confFile;
|
463 |
close($fh);
|
| 455 |
return $yaml->[0];
|
464 |
return \@lines;
|
| 456 |
}
|
465 |
}
|
| 457 |
die "Can not find $fileName in any of " . join( "\n\t", @searchPath ) . "\n";
|
466 |
die "Can not find $fileName in any of " . join( "\n\t", @{$searchPath} ) . "\n";
|
| 458 |
}
|
467 |
}
|
| 459 |
|
468 |
|
| 460 |
|
469 |
|
| 461 |
#######################################################
|
470 |
#######################################################
|
| 462 |
# function to simply log things
|
471 |
# function to simply log things
|
| Line 471... |
Line 480... |
| 471 |
sub logIt {
|
480 |
sub logIt {
|
| 472 |
my $configuration = shift;
|
481 |
my $configuration = shift;
|
| 473 |
my $priority = shift;
|
482 |
my $priority = shift;
|
| 474 |
|
483 |
|
| 475 |
# turn off variable checking so it doesn't blow up on lack of %configuration file
|
484 |
# turn off variable checking so it doesn't blow up on lack of %configuration file
|
| 476 |
#no strict 'vars';
|
485 |
# no strict 'vars';
|
| 477 |
return -1 unless exists $configuration->{'logging'};
|
486 |
return -1 unless exists $configuration->{'logging'};
|
| 478 |
return 2 unless $priority <= $configuration->{'logging'}->{'log level'};
|
487 |
return 2 unless $priority <= $configuration->{'logging'}->{'log level'};
|
| 479 |
if ( $configuration->{'logging'}->{'log type'} eq 'cache' ) {
|
488 |
if ( $configuration->{'logging'}->{'log type'} eq 'cache' ) {
|
| 480 |
push @{ $configuration->{'logging'}->{'cache'} }, @_;
|
489 |
push @{ $configuration->{'logging'}->{'cache'} }, @_;
|
| 481 |
return;
|
490 |
return;
|