Overview

Packages

  • log4php
    • appenders
    • configurators
    • filters
    • helpers
    • layouts
    • pattern
    • renderers

Classes

  • LoggerAppenderConsole
  • LoggerAppenderDailyFile
  • LoggerAppenderEcho
  • LoggerAppenderFile
  • LoggerAppenderFirePHP
  • LoggerAppenderMail
  • LoggerAppenderMailEvent
  • LoggerAppenderMongoDB
  • LoggerAppenderNull
  • LoggerAppenderPDO
  • LoggerAppenderPhp
  • LoggerAppenderRollingFile
  • LoggerAppenderSocket
  • LoggerAppenderSyslog
  • Overview
  • Package
  • Class
  • Tree

Class LoggerAppenderPDO

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.
LoggerConfigurable
Extended by LoggerAppender
Extended by LoggerAppenderPDO
Package: log4php\appenders
License: Apache License, Version 2.0
Version: $Revision: 1374546 $
Since: 2.0
Link: Appender documentation
Located at appenders/LoggerAppenderPDO.php
Methods summary
public
# activateOptions( )

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.

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.

Overrides

LoggerAppender::activateOptions()
protected
# establishConnection( )

Connects to the database, and prepares the insert query.

Connects to the database, and prepares the insert query.

Throws

PDOException
If connect or prepare fails.
public
# append( LoggerLoggingEvent $event )

Appends a new event to the database.

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.

Parameters

$event
LoggerLoggingEvent
$event
protected
# format( LoggerLoggingEvent $event )

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

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

public
# close( )

Closes the connection to the logging database

Closes the connection to the logging database

Overrides

LoggerAppender::close()
public PDO
# getDatabaseHandle( )

Returns the active database handle or null if not established.

Returns the active database handle or null if not established.

Returns

PDO
public
# setUser( mixed $user )

Sets the username.

Sets the username.

public
# getUser( mixed $user )

Returns the username.

Returns the username.

public
# setPassword( mixed $password )

Sets the password.

Sets the password.

public
# getPassword( mixed $password )

Returns the password.

Returns the password.

public
# setInsertSQL( mixed $sql )

Sets the insert SQL.

Sets the insert SQL.

public
# getInsertSQL( mixed $sql )

Returns the insert SQL.

Returns the insert SQL.

public
# setInsertPattern( mixed $pattern )

Sets the insert pattern.

Sets the insert pattern.

public
# getInsertPattern( mixed $pattern )

Returns the insert pattern.

Returns the insert pattern.

public
# setTable( mixed $table )

Sets the table name.

Sets the table name.

public
# getTable( mixed $table )

Returns the table name.

Returns the table name.

public
# setDSN( mixed $dsn )

Sets the DSN string.

Sets the DSN string.

public
# getDSN( mixed $dsn )

Returns the DSN string.

Returns the DSN string.

Methods inherited from LoggerAppender
__construct(), __destruct(), addFilter(), clearFilters(), doAppend(), getDefaultLayout(), getFilter(), getFirstFilter(), getLayout(), getName(), getThreshold(), isAsSevereAsThreshold(), requiresLayout(), setLayout(), setName(), setThreshold(), warn()
Methods inherited from LoggerConfigurable
setBoolean(), setFileSize(), setInteger(), setLevel(), setNumeric(), setPositiveInteger(), setString()
Properties summary
protected mixed $dsn
#

DSN string used to connect to the database.

DSN string used to connect to the database.

See

http://www.php.net/manual/en/pdo.construct.php
protected mixed $user
#

Database user name.

Database user name.

protected mixed $password
#

Database password.

Database password.

protected string $insertSQL "INSERT INTO __TABLE__ (timestamp, logger, level, message, thread, file, line) VALUES (?, ?, ?, ?, ?, ?, ?)"
#

The insert query.

The insert query.

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

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

protected string $insertPattern "%date{Y-m-d H:i:s},%logger,%level,%message,%pid,%file,%line"
#

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

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

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

See

LoggerPatternLayout For conversion patterns.
protected string $table 'log4php_log'
#

Name of the table to which to append log events.

Name of the table to which to append log events.

protected integer $reconnectAttempts 3
#

The number of recconect attempts to make on failed append.

The number of recconect attempts to make on failed append.

protected PDO $db
#

The PDO instance.

The PDO instance.

protected PDOStatement $preparedInsert
#

Prepared statement for the insert query.

Prepared statement for the insert query.

protected boolean $requiresLayout false
#

This appender does not require a layout.

This appender does not require a layout.

Properties inherited from LoggerAppender
$closed, $filter, $layout, $name, $threshold
Apache log4php API documentation generated by ApiGen 2.8.0