when detecting a down db connection, need to clear the stored sth as it is no longer valid.
This commit is contained in:
parent
63ede25647
commit
fc0369b9a4
|
@ -549,15 +549,23 @@ sub logPrint {
|
|||
print(STDERR $message) if $level <= $this->{termLevel};
|
||||
|
||||
if ( $level <= $this->{databaseLevel} ) {
|
||||
if ( ( $this->{dbh} and $this->{dbh}->ping() ) or ( $this->{dbh} = ZoneMinder::Database::zmDbConnect() ) ) {
|
||||
|
||||
if ( ! ( $this->{dbh} and $this->{dbh}->ping() ) ) {
|
||||
$this->{sth} = undef;
|
||||
if ( ! ( $this->{dbh} = ZoneMinder::Database::zmDbConnect() ) ) {
|
||||
print(STDERR "Can't log to database: ");
|
||||
$this->{databaseLevel} = NOLOG;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
my $sql = 'INSERT INTO Logs ( TimeKey, Component, Pid, Level, Code, Message, File, Line ) VALUES ( ?, ?, ?, ?, ?, ?, ?, NULL )';
|
||||
$this->{sth} = $this->{dbh}->prepare_cached($sql) if ! $this->{sth};
|
||||
if ( !$this->{sth} ) {
|
||||
$this->{databaseLevel} = NOLOG;
|
||||
Error("Can't prepare log entry '$sql': ".$this->{dbh}->errstr());
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
||||
my $res = $this->{sth}->execute($seconds+($microseconds/1000000.0)
|
||||
, $this->{id}
|
||||
, $$
|
||||
|
@ -570,10 +578,6 @@ sub logPrint {
|
|||
$this->{databaseLevel} = NOLOG;
|
||||
Error("Can't execute log entry '$sql': ".$this->{dbh}->errstr());
|
||||
}
|
||||
}
|
||||
} else {
|
||||
print(STDERR "Can't log to database: ");
|
||||
}
|
||||
} # end if doing db logging
|
||||
} # end if level < effectivelevel
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue