[pve-devel] [PATCH manager] Fix #482: Add timestamps to backup creation log
Thomas Lamprecht
t.lamprecht at proxmox.com
Thu Apr 11 12:05:54 CEST 2019
On 4/10/19 12:06 PM, Dominic Jäger wrote:
> Adding timestamps to the log messages facilitates troubleshooting
> failing backups.
> The current version already seems useful to me. A more advanced version
> with e.g. timezones and weekdays could be produced by additionaly
> using POSIX strftime or DateTime.
>
> Signed-off-by: Dominic Jäger <d.jaeger at proxmox.com>
> ---
> PVE/VZDump.pm | 13 +++++++++++--
> 1 file changed, 11 insertions(+), 2 deletions(-)
>
> diff --git a/PVE/VZDump.pm b/PVE/VZDump.pm
> index 7fc69f98..46767277 100644
> --- a/PVE/VZDump.pm
> +++ b/PVE/VZDump.pm
> @@ -833,7 +833,12 @@ sub exec_backup_task {
>
> unlink $logfile;
>
> - debugmsg ('info', "Starting Backup of VM $vmid ($vmtype)", $logfd, 1);
> +
> + my $start_time = localtime;
> + my $start_message = sprintf "[%04d-%02d-%02d %02d:%02d:%02d]",
> + $start_time->year+1900, $start_time->mon+1, $start_time->mday,
> + $start_time->hour, $start_time->min, $start_time->sec;
huh, why do you do this all?
How about keeping the debuginfo line above as is and just add a:
debug('info', "Backup started at " + strftime("%Y-%m-%d %H:%M:%S", localtime()), $logfd);
(no point in logging the date/time to syslog which already has date/time info there)
you would need to add
use POSIX qw(strftime);
but used base plugin module PVE::VZDump::Plugin has this already loaded, so it's not that
a new module would get loaded into this.
And even if not used as simple string use of localtime would be preferred over starting
to adding 1900 to years, etc, ;-)
same for end time
> + debugmsg ('info', "Starting Backup of VM $vmid ($vmtype) $start_message", $logfd, 1);
>
> $plugin->set_logfd ($logfd);
>
> @@ -1055,7 +1060,11 @@ sub exec_backup_task {
> } else {
> $task->{state} = 'ok';
> my $tstr = format_time ($delay);
> - debugmsg ('info', "Finished Backup of VM $vmid ($tstr)", $logfd, 1);
> + my $end_time = localtime;
> + my $end_message = sprintf "[%04d-%02d-%02d %02d:%02d:%02d]",
> + $end_time->year+1900, $end_time->mon+1, $end_time->mday,
> + $end_time->hour, $end_time->min, $end_time->sec;
> + debugmsg ('info', "Finished Backup of VM $vmid ($tstr) $end_message", $logfd, 1);
> }
>
> close ($logfd) if $logfd;
>
More information about the pve-devel
mailing list