Class LoggerAppenderPDO

Description

LoggerAppenderPDO appender logs to a database using the PHP's PDO extension.

## Configurable parameters: ##

  • dsn - The Data Source Name (DSN) used to connect to the database.
  • user - Username used to connect to the database.
  • password - Password used to connect to the database.
  • table - Name of the table to which log entries are be inserted.
  • insertSQL - Sets the insert statement for a logging event. Defaults to the correct one - change only if you are sure what you are doing.
  • insertPattern - The conversion pattern to use in conjuction with insert SQL. Must contain the same number of comma separated conversion patterns as there are question marks in the insertSQL.

Located in /log4php/appenders/LoggerAppenderPDO.php (line 42)

LoggerConfigurable
   |
   --LoggerAppender
      |
      --LoggerAppenderPDO
Variable Summary
PDO $db
mixed $dsn
mixed $insertSQL
mixed $password
PDOStatement $preparedInsert
mixed $table
mixed $user
Method Summary
void activateOptions ()
void append (LoggerLoggingEvent $event)
void close ()
void format (LoggerLoggingEvent $event)
void getDSN ( $dsn)
void getInsertPattern ( $pattern)
void getInsertSQL ( $sql)
void getPassword ( $password)
void getTable ( $table)
void getUser ( $user)
void setDSN ( $dsn)
void setInsertPattern ( $pattern)
void setInsertSQL ( $sql)
void setPassword ( $password)
void setTable ( $table)
void setUser ( $user)
Variables
PDO $db (line 97)

The PDO instance.

  • access: protected
mixed $dsn (line 52)

DSN string used to connect to the database.

mixed $insertPattern = "%date{Y-m-d H:i:s},%logger,%level,%message,%pid,%file,%line" (line 80)

A comma separated list of LoggerPatternLayout format strings which replace the "?" in $insertSQL.

Must contain the same number of comma separated conversion patterns as there are question marks in insertSQL.

  • see: LoggerPatternLayout For conversion patterns.
  • access: protected
mixed $insertSQL = "INSERT INTO __TABLE__ (timestamp, logger, level, message, thread, file, line) VALUES (?, ?, ?, ?, ?, ?, ?)" (line 69)

The insert query.

The __TABLE__ placeholder will be replaced by the table name from $table.

The questionmarks are part of the prepared statement, and they must match the number of conversion specifiers in insertPattern.

  • access: protected
mixed $password (line 58)

Database password.

  • access: protected
PDOStatement $preparedInsert (line 103)

Prepared statement for the insert query.

  • access: protected
mixed $reconnectAttempts = 3 (line 86)

The number of recconect attempts to make on failed append.

  • access: protected
mixed $requiresLayout = false (line 106)

This appender does not require a layout.

  • access: protected

Redefinition of:
LoggerAppender::$requiresLayout
Set to true if the appender requires a layout.
mixed $table = 'log4php_log' (line 83)

Name of the table to which to append log events.

  • access: protected
mixed $user (line 55)

Database user name.

  • access: protected

Inherited Variables

Inherited from LoggerAppender

LoggerAppender::$closed
LoggerAppender::$filter
LoggerAppender::$layout
LoggerAppender::$name
LoggerAppender::$threshold
Methods
activateOptions (line 118)

Acquires a database connection based on parameters.

Parses the insert pattern to create a chain of converters which will be used in forming query parameters from logging events.

  • access: public
void activateOptions ()

Redefinition of:
LoggerAppender::activateOptions()
Prepares the appender for logging.
append (line 159)

Appends a new event to the database.

If writing to database fails, it will retry by re-establishing the connection up to $reconnectAttempts times. If writing still fails, the appender will close.

  • access: public
void append (LoggerLoggingEvent $event)

Redefinition of:
LoggerAppender::append()
Forwards the logging event to the destination.
close (line 203)

Closes the connection to the logging database

  • access: public
void close ()

Redefinition of:
LoggerAppender::close()
Releases any resources allocated by the appender.
establishConnection (line 142)

Connects to the database, and prepares the insert query.

  • throws: PDOException If connect or prepare fails.
  • access: protected
void establishConnection ()
format (line 187)

Converts the logging event to a series of database parameters by using the converter chain which was set up on activation.

  • access: protected
void format (LoggerLoggingEvent $event)
getDatabaseHandle (line 219)

Returns the active database handle or null if not established.

  • access: public
PDO getDatabaseHandle ()
getDSN (line 279)

Returns the DSN string.

  • access: public
void getDSN ( $dsn)
  • $dsn
getInsertPattern (line 259)

Returns the insert pattern.

  • access: public
void getInsertPattern ( $pattern)
  • $pattern
getInsertSQL (line 249)

Returns the insert SQL.

  • access: public
void getInsertSQL ( $sql)
  • $sql
getPassword (line 239)

Returns the password.

  • access: public
void getPassword ( $password)
  • $password
getTable (line 269)

Returns the table name.

  • access: public
void getTable ( $table)
  • $table
getUser (line 229)

Returns the username.

  • access: public
void getUser ( $user)
  • $user
setDSN (line 274)

Sets the DSN string.

  • access: public
void setDSN ( $dsn)
  • $dsn
setInsertPattern (line 254)

Sets the insert pattern.

  • access: public
void setInsertPattern ( $pattern)
  • $pattern
setInsertSQL (line 244)

Sets the insert SQL.

  • access: public
void setInsertSQL ( $sql)
  • $sql
setPassword (line 234)

Sets the password.

  • access: public
void setPassword ( $password)
  • $password
setTable (line 264)

Sets the table name.

  • access: public
void setTable ( $table)
  • $table
setUser (line 224)

Sets the username.

  • access: public
void setUser ( $user)
  • $user

Inherited Methods

Inherited From LoggerAppender

LoggerAppender::__construct()
LoggerAppender::activateOptions()
LoggerAppender::addFilter()
LoggerAppender::append()
LoggerAppender::clearFilters()
LoggerAppender::close()
LoggerAppender::doAppend()
LoggerAppender::getDefaultLayout()
LoggerAppender::getFilter()
LoggerAppender::getFirstFilter()
LoggerAppender::getLayout()
LoggerAppender::getName()
LoggerAppender::getThreshold()
LoggerAppender::isAsSevereAsThreshold()
LoggerAppender::requiresLayout()
LoggerAppender::setLayout()
LoggerAppender::setName()
LoggerAppender::setThreshold()
LoggerAppender::warn()
LoggerAppender::__destruct()

Inherited From LoggerConfigurable

LoggerConfigurable::setBoolean()
LoggerConfigurable::setFileSize()
LoggerConfigurable::setInteger()
LoggerConfigurable::setLevel()
LoggerConfigurable::setNumeric()
LoggerConfigurable::setPositiveInteger()
LoggerConfigurable::setString()
LoggerConfigurable::warn()

Documentation generated on Tue, 12 Mar 2024 14:04:52 +0900 by phpDocumentor 1.4.4