Logging fixes
gitea/vn-vmware/master This commit looks good
Details
gitea/vn-vmware/master This commit looks good
Details
This commit is contained in:
parent
482613b105
commit
66c97bb570
|
@ -1,4 +1,4 @@
|
|||
vn-vmware (1.1.15) stable; urgency=low
|
||||
vn-vmware (1.1.17) stable; urgency=low
|
||||
|
||||
* Initial Release.
|
||||
|
||||
|
|
61
vn-vmware.pl
61
vn-vmware.pl
|
@ -181,39 +181,44 @@ my $backup_disks;
|
|||
my $time_pattern = '%Y-%m-%d_%H-%M';
|
||||
my $local_backup_dir = $config{local_backup_dir};
|
||||
|
||||
sub stringify_message {
|
||||
my ($message) = @_;
|
||||
|
||||
if ($message->isa('SoapFault')) {
|
||||
my $detail = ref $message->detail;
|
||||
$message = "SoapFault: $detail: $message->{fault_string}";
|
||||
}
|
||||
unless (substr($message, -1) eq "\n") {
|
||||
$message .= "\n";
|
||||
}
|
||||
|
||||
return ($message);
|
||||
}
|
||||
|
||||
sub log_to_file {
|
||||
my ($message) = @_;
|
||||
my $time = Time::Piece->new;
|
||||
my $time_mark = $time->strftime('%Y-%m-%d %H:%M:%S');
|
||||
print $log_fh "$time_mark $message";
|
||||
|
||||
if ($log_fh) {
|
||||
my $time = Time::Piece->new;
|
||||
my $time_mark = $time->strftime('%Y-%m-%d %H:%M:%S');
|
||||
print $log_fh "$time_mark $message";
|
||||
}
|
||||
}
|
||||
|
||||
sub log_message {
|
||||
my ($message) = @_;
|
||||
|
||||
Util::trace(1, "$message\n");
|
||||
|
||||
if ($log_fh) {
|
||||
log_to_file "LOG: $message\n";
|
||||
}
|
||||
$message = stringify_message($message);
|
||||
Util::trace(1, $message);
|
||||
log_to_file "LOG: $message";
|
||||
}
|
||||
|
||||
sub log_error {
|
||||
my ($error) = @_;
|
||||
|
||||
if ($error->isa('SoapFault')) {
|
||||
my $detail = ref $error->detail;
|
||||
$error = "SoapFault: $detail: $error->{fault_string}";
|
||||
}
|
||||
unless (substr($error, -1) eq "\n") {
|
||||
$error .= "\n";
|
||||
}
|
||||
|
||||
$error = stringify_message($error);
|
||||
print STDERR $error;
|
||||
|
||||
if ($log_fh) {
|
||||
log_to_file "ERR: $error";
|
||||
}
|
||||
log_to_file "ERR: $error";
|
||||
}
|
||||
|
||||
if (exists $config{log_file}) {
|
||||
|
@ -313,16 +318,18 @@ sub backup_job() {
|
|||
|
||||
my $backup_job = $config{backup_jobs}{$job};
|
||||
my @machines = @{$backup_job->{machines}};
|
||||
|
||||
my $default_rotation;
|
||||
|
||||
if (exists $backup_job->{rotation}) {
|
||||
$default_rotation = $backup_job->{rotation};
|
||||
} elsif (exists $config{rotation}) {
|
||||
$default_rotation = $config{rotation};
|
||||
}
|
||||
|
||||
foreach my $machine (@machines) {
|
||||
eval {
|
||||
my $rotation_name;
|
||||
|
||||
if (exists $backup_job->{rotation}) {
|
||||
$rotation_name = $backup_job->{rotation};
|
||||
} elsif (exists $config{rotation}) {
|
||||
$rotation_name = $config{rotation};
|
||||
}
|
||||
my $rotation_name = $default_rotation;
|
||||
|
||||
if (ref($machine) eq 'HASH') {
|
||||
$vm_name = $machine->{name};
|
||||
|
|
Reference in New Issue