| <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
| <!-- Generated by Apache Maven Doxia at Oct 13, 2012 --> |
| <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> |
| <head> |
| <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> |
| <title>Apache log4php - |
| LoggerAppenderPDO - Apache log4php</title> |
| <link rel="stylesheet" href="../../css/bootstrap.min.css" type="text/css" /> |
| <link rel="stylesheet" href="../../css/site.css" type="text/css" /> |
| <script type="text/javascript" src="../../js/jquery.min.js"></script> |
| <script type="text/javascript" src="../../js/bootstrap.min.js"></script> |
| <script type="text/javascript" src="../../js/prettify.min.js"></script> |
| <script type="text/javascript" src="../../js/site.js"></script> |
| <meta name="Date-Revision-yyyymmdd" content="20121013" /> |
| <meta http-equiv="Content-Language" content="en" /> |
| |
| <!-- Google Analytics --> |
| <script type="text/javascript"> |
| |
| var _gaq = _gaq || []; |
| _gaq.push(['_setAccount', 'UA-26177991-1']); |
| _gaq.push (['_gat._anonymizeIp']); |
| _gaq.push(['_trackPageview']); |
| |
| (function() { |
| var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; |
| ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; |
| var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); |
| })(); |
| |
| </script> |
| </head> |
| <body class="composite"> |
| |
| <div class="navbar"> |
| <div class="navbar-inner"> |
| <div class="container-fluid"> |
| <a class="brand" href="http://logging.apache.org/log4php">Apache log4php ™</a> |
| <ul class="nav"> |
| <li> |
| <a href="../../index.html" title="About">About</a> |
| </li> |
| <li> |
| <a href="../../download.html" title="Download">Download</a> |
| </li> |
| <li> |
| <a href="../../install.html" title="Install">Install</a> |
| </li> |
| <li> |
| <a href="../../quickstart.html" title="Quick start">Quick start</a> |
| </li> |
| </ul> |
| |
| <!-- Twitter link --> |
| <ul class="nav pull-right"> |
| <li><a href="http://twitter.com/log4php/" class="external">Follow <strong>@log4php</strong></a></li> |
| </ul> |
| |
| <!-- Google CSE Search Box --> |
| <form class="navbar-search pull-right" id="cref" action="http://www.google.com/cse"> |
| <input type="hidden" name="cref" value="http://logging.apache.org/log4php/cse.xml" /> |
| <input class="search-query pull-left" type="text" name="q" size="40" placeholder="Search" /> |
| </form> |
| </div> |
| </div> |
| </div> |
| |
| <div class="container-fluid"> |
| <table class="layout-table"> |
| <tr> |
| <td class="sidebar"> |
| <div class="well sidebar-nav"> |
| <ul class="nav nav-list"> |
| <li class="nav-header"><i class="icon-home"></i>Apache log4php™</li> |
| <li class="none"> |
| <a href="../../index.html" title="About">About</a> |
| </li> |
| <li class="none"> |
| <a href="../../download.html" title="Download">Download</a> |
| </li> |
| <li class="none"> |
| <a href="../../install.html" title="Install">Install</a> |
| </li> |
| <li class="none"> |
| <a href="../../changelog.html" title="Changelog">Changelog</a> |
| </li> |
| </ul> |
| <ul class="nav nav-list"> |
| <li class="nav-header"><i class="icon-book"></i>Documentation</li> |
| <li class="none"> |
| <a href="../../quickstart.html" title="Quick start">Quick start</a> |
| </li> |
| <li class="none"> |
| <a href="../../docs/introduction.html" title="Introduction">Introduction</a> |
| </li> |
| <li class="none"> |
| <a href="../../docs/configuration.html" title="Configuration">Configuration</a> |
| </li> |
| <li class="none"> |
| <a href="../../docs/loggers.html" title="Loggers">Loggers</a> |
| </li> |
| <li class="expanded"> |
| <a href="../../docs/appenders.html" title="Appenders">Appenders</a> |
| <ul> |
| <li class="none"> |
| <a href="../../docs/appenders/console.html" title="LoggerAppenderConsole">LoggerAppenderConsole</a> |
| </li> |
| <li class="none"> |
| <a href="../../docs/appenders/daily-file.html" title="LoggerAppenderDailyFile">LoggerAppenderDailyFile</a> |
| </li> |
| <li class="none"> |
| <a href="../../docs/appenders/echo.html" title="LoggerAppenderEcho">LoggerAppenderEcho</a> |
| </li> |
| <li class="none"> |
| <a href="../../docs/appenders/file.html" title="LoggerAppenderFile">LoggerAppenderFile</a> |
| </li> |
| <li class="none"> |
| <a href="../../docs/appenders/firephp.html" title="LoggerAppenderFirePHP">LoggerAppenderFirePHP</a> |
| </li> |
| <li class="none"> |
| <a href="../../docs/appenders/mail.html" title="LoggerAppenderMail">LoggerAppenderMail</a> |
| </li> |
| <li class="none"> |
| <a href="../../docs/appenders/mail-event.html" title="LoggerAppenderMailEvent">LoggerAppenderMailEvent</a> |
| </li> |
| <li class="none"> |
| <a href="../../docs/appenders/mongodb.html" title="LoggerAppenderMongoDB">LoggerAppenderMongoDB</a> |
| </li> |
| <li class="none"> |
| <a href="../../docs/appenders/null.html" title="LoggerAppenderNull">LoggerAppenderNull</a> |
| </li> |
| <li class="none active"> |
| <a href="../../docs/appenders/pdo.html" title="LoggerAppenderPDO">LoggerAppenderPDO</a> |
| </li> |
| <li class="none"> |
| <a href="../../docs/appenders/php.html" title="LoggerAppenderPHP">LoggerAppenderPHP</a> |
| </li> |
| <li class="none"> |
| <a href="../../docs/appenders/rolling-file.html" title="LoggerAppenderRollingFile">LoggerAppenderRollingFile</a> |
| </li> |
| <li class="none"> |
| <a href="../../docs/appenders/socket.html" title="LoggerAppenderSocket">LoggerAppenderSocket</a> |
| </li> |
| <li class="none"> |
| <a href="../../docs/appenders/syslog.html" title="LoggerAppenderSyslog">LoggerAppenderSyslog</a> |
| </li> |
| </ul> |
| </li> |
| <li class="collapsed"> |
| <a href="../../docs/layouts.html" title="Layouts">Layouts</a> |
| </li> |
| <li class="none"> |
| <a href="../../docs/filters.html" title="Filters">Filters</a> |
| </li> |
| <li class="none"> |
| <a href="../../docs/renderers.html" title="Renderers">Renderers</a> |
| </li> |
| <li class="none"> |
| <a href="../../apidocs/index.html" title="API documentation">API documentation</a> |
| </li> |
| </ul> |
| <ul class="nav nav-list"> |
| <li class="nav-header"><i class="icon-user"></i>Community</li> |
| <li class="none"> |
| <a href="../../volunteering.html" title="Volunteering">Volunteering</a> |
| </li> |
| <li class="none"> |
| <a href="../../contributingpatches.html" title="Contributing Patches">Contributing Patches</a> |
| </li> |
| <li class="none"> |
| |
| |
| <a href="http://wiki.apache.org/logging-log4php" class="external" target="_blank" title="Wiki">Wiki</a> |
| </li> |
| <li class="none"> |
| |
| |
| <a href="http://blogs.apache.org/logging/" class="external" target="_blank" title="Blog">Blog</a> |
| </li> |
| </ul> |
| <ul class="nav nav-list"> |
| <li class="nav-header"><i class="icon-info-sign"></i>Project Information</li> |
| <li class="none"> |
| <a href="../../integration.html" title="Continuous Integration">Continuous Integration</a> |
| </li> |
| <li class="none"> |
| <a href="../../source-repository.html" title="Source Repository">Source Repository</a> |
| </li> |
| <li class="none"> |
| <a href="../../dependencies.html" title="Dependencies">Dependencies</a> |
| </li> |
| <li class="none"> |
| <a href="../../license.html" title="Project License">Project License</a> |
| </li> |
| <li class="none"> |
| <a href="../../team-list.html" title="Project Team">Project Team</a> |
| </li> |
| <li class="none"> |
| <a href="../../issue-tracking.html" title="Issue Tracking">Issue Tracking</a> |
| </li> |
| <li class="none"> |
| <a href="../../mail-lists.html" title="Mailing Lists">Mailing Lists</a> |
| </li> |
| </ul> |
| <ul class="nav nav-list"> |
| <li class="nav-header"><i class="icon-cog"></i>Project Reports</li> |
| <li class="none"> |
| <a href="../../changes-report.html" title="Changes Report">Changes Report</a> |
| </li> |
| <li class="none"> |
| <a href="../../surefire-report.html" title="Surefire Report">Surefire Report</a> |
| </li> |
| <li class="none"> |
| <a href="../../rat-report.html" title="RAT Report">RAT Report</a> |
| </li> |
| <li class="none"> |
| <a href="../../coverage-report/index.html" title="Code Coverage">Code Coverage</a> |
| </li> |
| </ul> |
| <ul class="nav nav-list"> |
| <li class="nav-header"><i class="icon-heart"></i>Apache</li> |
| <li class="none"> |
| |
| |
| <a href="http://www.apache.org" class="external" target="_blank" title="Home">Home</a> |
| </li> |
| <li class="none"> |
| |
| |
| <a href="http://www.apache.org/foundation/sponsorship.html" class="external" target="_blank" title="Sponsorship">Sponsorship</a> |
| </li> |
| <li class="none"> |
| |
| |
| <a href="http://www.apache.org/licenses/" class="external" target="_blank" title="License">License</a> |
| </li> |
| <li class="none"> |
| |
| |
| <a href="http://www.apache.org/foundation/thanks.html" class="external" target="_blank" title="Thanks">Thanks</a> |
| </li> |
| <li class="none"> |
| |
| |
| <a href="http://www.apachecon.com" class="external" target="_blank" title="Conferences">Conferences</a> |
| </li> |
| <li class="none"> |
| |
| |
| <a href="http://www.apache.org/security/" class="external" target="_blank" title="Security">Security</a> |
| </li> |
| </ul> |
| </div> |
| <div id="poweredBy"> |
| <a href="http://maven.apache.org/" title="Built by Maven" class="poweredBy"> |
| <img class="poweredBy" alt="Built by Maven" src="../../images/logos/maven-feather.png" /> |
| </a> |
| </div> |
| </td> |
| <td class="content"> |
| <!-- Licensed to the Apache Software Foundation (ASF) under one or more |
| contributor license agreements. See the NOTICE file distributed with |
| this work for additional information regarding copyright ownership. |
| The ASF licenses this file to You under the Apache License, Version 2.0 |
| (the "License"); you may not use this file except in compliance with |
| the License. You may obtain a copy of the License at |
| |
| http://www.apache.org/licenses/LICENSE-2.0 |
| |
| Unless required by applicable law or agreed to in writing, software |
| distributed under the License is distributed on an "AS IS" BASIS, |
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| See the License for the specific language governing permissions and |
| limitations under the License. --> |
| |
| |
| <div class="section"><h2>LoggerAppenderPDO<a name="LoggerAppenderPDO"></a></h2> |
| |
| <p><tt>LoggerAppenderPDO</tt> appender logs to a database using the PHP's |
| <a class="external" href="http://php.net/manual/en/book.pdo.php">PDO extension</a>.</p> |
| |
| <div class="section"><h3>Layout<a name="Layout"></a></h3> |
| <p>This appender does not require a layout.</p> |
| </div> |
| |
| <div class="section"><h3>Parameters<a name="Parameters"></a></h3> |
| <p>The following parameters are available:</p> |
| |
| <table border="0" class="bodyTable"> |
| <thead> |
| <tr class="a"> |
| <th>Parameter</th> |
| <th>Type</th> |
| <th>Required</th> |
| <th>Default</th> |
| <th>Description</th> |
| </tr> |
| </thead> |
| <tbody> |
| <tr class="b"> |
| <td>dsn</td> |
| <td>string</td> |
| <td><b>Yes</b></td> |
| <td>-</td> |
| <td>The Data Source Name (DSN) used to connect to the database.</td> |
| </tr> |
| <tr class="a"> |
| <td>user</td> |
| <td>string</td> |
| <td><b>Yes</b></td> |
| <td>-</td> |
| <td>Username used to connect to the database.</td> |
| </tr> |
| <tr class="b"> |
| <td>password</td> |
| <td>string</td> |
| <td><b>Yes</b></td> |
| <td>-</td> |
| <td>Password used to connect to the database.</td> |
| </tr> |
| <tr class="a"> |
| <td>table</td> |
| <td>string</td> |
| <td>No</td> |
| <td>-</td> |
| <td>Name of the table to which log entries are be inserted.</td> |
| </tr> |
| <tr class="b"> |
| <td>insertSql</td> |
| <td>string</td> |
| <td>No</td> |
| <td><i><a href="#Advanced_configuration">see below</a></i></td> |
| <td>SQL query used to insert a log event.</td> |
| </tr> |
| <tr class="a"> |
| <td>insertPattern</td> |
| <td>string</td> |
| <td>No</td> |
| <td><i><a href="#Advanced_configuration">see below</a></i></td> |
| <td>A comma separated list of format strings used in conjunction with <tt>insertSql</tt> parameter.</td> |
| </tr> |
| </tbody> |
| </table> |
| |
| <p>Parameters <tt>dsn</tt>, <tt>user</tt> and <tt>password</tt> are used by PDO to connect to |
| the database which will be used for logging.</p> |
| </div> |
| |
| <div class="section"><h3>Data Source Name<a name="Data_Source_Name"></a></h3> |
| <p>The Data Source Name or DSN is a database-specific string which contains the information required |
| to connect to the database.</p> |
| |
| <p>Some common examples of DSNs:</p> |
| |
| <table border="0" class="table table-compact table-bordered table-not-wide"> |
| <tbody> |
| <tr class="a"> |
| <th>MySQL</th> |
| <td><tt>mysql:host=localhost;dbname=logdb</tt></td> |
| <td><a class="external" href="http://php.net/manual/en/ref.pdo-mysql.connection.php">full reference</a> </td> |
| </tr> |
| <tr class="b"> |
| <th>SQLite</th> |
| <td><tt>sqlite:/path/to/log.db</tt></td> |
| <td><a class="external" href="http://php.net/manual/en/ref.pdo-sqlite.connection.php">full reference</a> </td> |
| </tr> |
| <tr class="a"> |
| <th>PostgreSQL </th> |
| <td><tt>pgsql:host=localhost;port=5432</tt></td> |
| <td><a class="external" href="http://php.net/manual/en/ref.pdo-pgsql.connection.php">full reference</a> </td> |
| </tr> |
| </tbody> |
| </table> |
| |
| <p>For other available database drivers and corresponding DSN format, please see the |
| <a class="external" href="http://www.php.net/manual/en/pdo.drivers.php">PDO driver documentation</a>. |
| </p> |
| </div> |
| |
| <div class="section"><h3>Database table<a name="Database_table"></a></h3> |
| |
| <p>Since version 2.3.0, the appender will <b>not</b> create a database table by itself. You |
| have to create a database table yourself. The reason for this is that various databases use various |
| create statements and column types. Some common databases are covered in this chapter.</p> |
| |
| <p>By default the table should contain the following columns: </p> |
| |
| <ul> |
| <li>timestamp DATETIME</li> |
| <li>logger VARCHAR</li> |
| <li>level VARCHAR</li> |
| <li>message VARCHAR</li> |
| <li>thread VARCHAR</li> |
| <li>file VARCHAR</li> |
| <li>line VARCHAR</li> |
| </ul> |
| |
| <p>If you wish to use an alternative table structure, see the next chapter.</p> |
| |
| <p>The following examples show CREATE TABLE statements for some popular databases.</p> |
| |
| <div class="section"><h4>MySQL<a name="MySQL"></a></h4> |
| |
| <div><pre class="prettyprint"> |
| CREATE TABLE log4php_log ( |
| timestamp DATETIME, |
| logger VARCHAR(256), |
| level VARCHAR(32), |
| message VARCHAR(4000), |
| thread INTEGER, |
| file VARCHAR(255), |
| line VARCHAR(10) |
| ); |
| </pre></div> |
| |
| </div><div class="section"><h4>SQLite<a name="SQLite"></a></h4> |
| |
| <p>SQLite does not have a datetime type, so varchar is used instead.</p> |
| |
| <div><pre class="prettyprint"> |
| CREATE TABLE log4php_log ( |
| timestamp VARCHAR(50), |
| logger VARCHAR(256), |
| level VARCHAR(32), |
| message VARCHAR(4000), |
| thread INTEGER, |
| file VARCHAR(255), |
| line VARCHAR(10) |
| ); |
| </pre></div> |
| |
| </div><div class="section"><h4>PostgreSQL<a name="PostgreSQL"></a></h4> |
| |
| <div><pre class="prettyprint"> |
| CREATE TABLE log4php_log ( |
| timestamp TIMESTAMP, |
| logger VARCHAR(256), |
| level VARCHAR(32), |
| message VARCHAR(4000), |
| thread INTEGER, |
| file VARCHAR(255), |
| line VARCHAR(10) |
| ); |
| </pre></div> |
| </div></div> |
| |
| <a name="Advanced_configuration"></a><div class="section" id="Advanced_configuration"><h3>Advanced configuration<a name="Advanced_configuration"></a></h3> |
| <p>Parameters <tt>insertSql</tt> and <tt>insertPattern</tt> can be used to change how events are |
| inserted into the database. By manipulating them, it is possible to use a custom table structure to |
| suit your needs.</p> |
| |
| <p class="alert alert-warning"><b>WARNING:</b> Change these settings only if you are sure you |
| know what you are doing.</p> |
| |
| <p>The default values of these parameters are:</p> |
| |
| <table border="0" class="bodyTable"> |
| <thead> |
| <tr class="a"> |
| <th>Parameter</th> |
| <th>Default value</th> |
| </tr> |
| </thead> |
| <tbody> |
| <tr class="b"> |
| <td>insertSql</td> |
| <td>INSERT INTO __TABLE__ (timestamp, logger, level, message, thread, file, line) VALUES (?, ?, ?, ?, ?, ?, ?)</td> |
| </tr> |
| <tr class="a"> |
| <td>insertPattern</td> |
| <td>%date{Y-m-d H:i:s},%logger,%level,%message,%pid,%file,%line</td> |
| </tr> |
| </tbody> |
| </table> |
| |
| <p>The string <i>__TABLE__</i> in <tt>insertSql</tt> will be replaced with the table name |
| defined in <tt>table</tt>. Question marks in <tt>insertSql</tt> will be replaced by evaluated |
| <tt><a href="../layouts/pattern.html">LoggerPatternLayout</a></tt> format strings defined in |
| <tt>insertPattern</tt>. See <tt><a href="../layouts/pattern.html">LoggerPatternLayout</a></tt> |
| documentation for format string description.</p> |
| |
| </div> |
| |
| |
| <div class="section"><h3>Examples<a name="Examples"></a></h3> |
| |
| <div class="section"><h4>Example 1<a name="Example_1"></a></h4> |
| |
| <p>The simplest example is connecting to an SQLite database which does not require any |
| authentication.</p> |
| |
| <p>SQLite databases are contained in simple files and don't reuquire a server to run. This example will |
| log to the database contained in <tt>/var/log/log.sqlite</tt>.</p> |
| |
| <p>First, create a database and a table for logging. In this example, let's create the database at |
| <tt>/tmp/log.db</tt>.</p> |
| |
| <div><pre> |
| $ sqlite3 /tmp/log.db |
| SQLite version 3.7.9 2011-11-01 00:52:41 |
| Enter ".help" for instructions |
| Enter SQL statements terminated with a ";" |
| sqlite> CREATE TABLE log4php_log ( |
| ...> timestamp VARCHAR(256), |
| ...> logger VARCHAR(256), |
| ...> level VARCHAR(32), |
| ...> message VARCHAR(4000), |
| ...> thread INTEGER, |
| ...> file VARCHAR(255), |
| ...> line VARCHAR(10) |
| ...> ); |
| </pre></div> |
| |
| <p>When the database is set up, use the following configuration to set up log4php.</p> |
| |
| <div class="auto-tabs"> |
| <ul> |
| <li>XML</li> |
| <li>PHP</li> |
| </ul> |
| |
| <div class="tab-content"> |
| <div class="tab-pane"> |
| <div><pre class="prettyprint"> |
| <configuration xmlns="http://logging.apache.org/log4php/"> |
| <appender name="default" class="LoggerAppenderPDO"> |
| <param name="dsn" value="sqlite:/tmp/log.db" /> |
| </appender> |
| <root> |
| <appender_ref ref="default" /> |
| </root> |
| </configuration> |
| </pre></div> |
| </div> |
| <div class="tab-pane"> |
| <div><pre class="prettyprint"> |
| array( |
| 'appenders' => array( |
| 'default' => array( |
| 'class' => 'LoggerAppenderPDO', |
| 'params' => array( |
| 'dsn' => 'sqlite:/tmp/log.db', |
| ), |
| ), |
| ), |
| 'rootLogger' => array( |
| 'appenders' => array('default'), |
| ), |
| ); |
| </pre></div> |
| </div> |
| </div> |
| </div> |
| |
| <p>Now the database is ready to accept some logging data.</p> |
| |
| <div><pre class="prettyprint linenums"> |
| require 'log4php/Logger.php'; |
| Logger::configure('config.xml'); |
| |
| $log = Logger::getLogger('foo'); |
| $log->info("foo"); |
| $log->info("bar"); |
| $log->info("baz"); |
| </pre></div> |
| |
| <p>And you can .</p> |
| |
| <div><pre> |
| $ sqlite3 /tmp/log.db |
| SQLite version 3.7.9 2011-11-01 00:52:41 |
| Enter ".help" for instructions |
| Enter SQL statements terminated with a ";" |
| sqlite> select * from log4php_log; |
| 2012-08-18 17:14:11|foo|INFO|foo|23531|/home/ihabunek/apache/sqlite.php|5 |
| 2012-08-18 17:14:11|foo|INFO|bar|23531|/home/ihabunek/apache/sqlite.php|6 |
| 2012-08-18 17:14:11|foo|INFO|baz|23531|/home/ihabunek/apache/sqlite.php|7 |
| </pre></div> |
| |
| </div><div class="section"><h4>Example 2<a name="Example_2"></a></h4> |
| |
| <p>A slightly more complex example is connecting to a MySQL database which requires user credentials |
| to be provided. Additionally, a user-specified table name is used.</p> |
| |
| <p>First, a log table has to be created. For this example a database named <tt>logdb</tt> will be |
| created, and within it a table named <tt>log</tt>.</p> |
| |
| <div><pre> |
| $ mysql -u root -p |
| Enter password: ******* |
| Welcome to the MySQL monitor. Commands end with ; or \g. |
| Your MySQL connection id is 47 |
| Server version: 5.5.24-0ubuntu0.12.04.1 (Ubuntu) |
| |
| mysql> CREATE DATABASE logdb; |
| Query OK, 1 row affected (0.00 sec) |
| |
| mysql> USE logdb; |
| Database changed |
| |
| mysql> CREATE TABLE log ( |
| -> timestamp DATETIME, |
| -> logger VARCHAR(256), |
| -> level VARCHAR(32), |
| -> message VARCHAR(4000), |
| -> thread INTEGER, |
| -> file VARCHAR(255), |
| -> line VARCHAR(10) |
| -> ); |
| Query OK, 0 rows affected (0.01 sec) |
| </pre></div> |
| |
| <p>The following configuration allows log4php to write to the newly created table.</p> |
| |
| <div class="auto-tabs"> |
| <ul> |
| <li>XML</li> |
| <li>PHP</li> |
| </ul> |
| |
| <div class="tab-content"> |
| <div class="tab-pane"> |
| <div><pre class="prettyprint"> |
| <configuration xmlns="http://logging.apache.org/log4php/"> |
| <appender name="default" class="LoggerAppenderPDO"> |
| <param name="dsn" value="mysql:host=localhost;dbname=logdb" /> |
| <param name="user" value="root" /> |
| <param name="password" value="secret" /> |
| <param name="table" value="log" /> |
| </appender> |
| <root> |
| <appender_ref ref="default" /> |
| </root> |
| </configuration> |
| </pre></div> |
| </div> |
| <div class="tab-pane"> |
| <div><pre class="prettyprint"> |
| array( |
| 'appenders' => array( |
| 'default' => array( |
| 'class' => 'LoggerAppenderPDO', |
| 'params' => array( |
| 'dsn' => 'mysql:host=localhost;dbname=logdb', |
| 'user' => 'root', |
| 'password' => 'secret', |
| 'table' => 'log', |
| ), |
| ), |
| ), |
| 'rootLogger' => array( |
| 'appenders' => array('default'), |
| ), |
| ); |
| </pre></div> |
| </div> |
| </div> |
| </div> |
| |
| <p>Now the database is ready to accept some logging data.</p> |
| |
| <div><pre class="prettyprint linenums"> |
| require 'log4php/Logger.php'; |
| Logger::configure('config.xml'); |
| |
| $log = Logger::getLogger('main'); |
| $log->info("foo"); |
| $log->info("bar"); |
| $log->info("baz"); |
| </pre></div> |
| |
| <p>Finally, to see the newly logged data.</p> |
| |
| <div><pre> |
| $ mysql -u root -p |
| Enter password: ******* |
| Welcome to the MySQL monitor. Commands end with ; or \g. |
| Your MySQL connection id is 47 |
| Server version: 5.5.24-0ubuntu0.12.04.1 (Ubuntu) |
| |
| mysql> select * from log; |
| +---------------------+--------+-------+---------+--------+---------------------------------+------+ |
| | timestamp | logger | level | message | thread | file | line | |
| +---------------------+--------+-------+---------+--------+---------------------------------+------+ |
| | 2012-08-18 17:30:05 | main | INFO | foo | 23638 | /home/ihabunek/apache/mysql.php | 5 | |
| | 2012-08-18 17:30:05 | main | INFO | bar | 23638 | /home/ihabunek/apache/mysql.php | 6 | |
| | 2012-08-18 17:30:05 | main | INFO | baz | 23638 | /home/ihabunek/apache/mysql.php | 7 | |
| +---------------------+--------+-------+---------+--------+---------------------------------+------+ |
| 3 rows in set (0.00 sec) |
| </pre></div> |
| |
| </div></div> |
| </div> |
| |
| |
| </td> |
| </tr> |
| </table> |
| </div> |
| |
| <div class="footer"> |
| <p>Copyright © 2012 |
| <a href="http://www.apache.org">Apache Software Foundation</a>. |
| All Rights Reserved. |
| |
| Licensed under the <a href="http://www.apache.org/licenses/LICENSE-2.0">Apache Software License, Version 2.0</a>. |
| Please read the <a href="../../privacy.html">Privacy policy</a></p> |
| <p>Apache log4php, Apache, log4php, the Apache feather logo, the Apache Logging Services project logo and the Built by |
| Maven logo are trademarks of The Apache Software Foundation.</p> |
| <p>Site powered by <a class="external" href="http://twitter.github.com/bootstrap/">Twitter Bootstrap</a>. Icons from |
| <a class="external" href="http://glyphicons.com/">Glyphicons Free</a>.</p> |
| </div> |
| </body> |
| </html> |