| <!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 Feb 18, 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> |
| Appenders - 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="20120218" /> |
| <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="#">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="externalLink">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 active"> |
| <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/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"> |
| <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="externalLink" target="_blank" title="Wiki">Wiki</a> |
| </li> |
| <li class="none"> |
| |
| |
| <a href="http://blogs.apache.org/logging/" class="externalLink" 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="externalLink" target="_blank" title="Home">Home</a> |
| </li> |
| <li class="none"> |
| |
| |
| <a href="http://www.apache.org/foundation/sponsorship.html" class="externalLink" target="_blank" title="Sponsorship">Sponsorship</a> |
| </li> |
| <li class="none"> |
| |
| |
| <a href="http://www.apache.org/licenses/" class="externalLink" target="_blank" title="License">License</a> |
| </li> |
| <li class="none"> |
| |
| |
| <a href="http://www.apache.org/foundation/thanks.html" class="externalLink" target="_blank" title="Thanks">Thanks</a> |
| </li> |
| <li class="none"> |
| |
| |
| <a href="http://www.apachecon.com" class="externalLink" target="_blank" title="Conferences">Conferences</a> |
| </li> |
| <li class="none"> |
| |
| |
| <a href="http://www.apache.org/security/" class="externalLink" 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>Appenders<a name="Appenders"></a></h2> |
| |
| <p>Logging requests can be sent to multiple destinations, such as files, databases, syslog and others. |
| Such destinations are called appenders. Appenders are attached to <a href="loggers.html">loggers</a> |
| and each logger can have multiple attached appenders.</p> |
| |
| <a name="Appender_reference"></a><div class="section"><h3 id="Appender_reference">Appender reference</h3> |
| |
| <p>The following appender classes are available:</p> |
| |
| <table border="0" class="bodyTable"> |
| <thead> |
| <tr class="a"> |
| <th>Name</th> |
| <th>Destination</th> |
| </tr> |
| </thead> |
| <tbody> |
| <tr class="b"> |
| <td><a href="appenders/console.html">LoggerAppenderConsole</a></td> |
| <td>Console, directly to the stdout or stderr stream.</td> |
| </tr> |
| <tr class="a"> |
| <td><a href="appenders/echo.html">LoggerAppenderEcho</a></td> |
| <td>Console, using the PHP <tt>echo</tt> command.</td> |
| </tr> |
| <tr class="b"> |
| <td><a href="appenders/file.html">LoggerAppenderFile</a></td> |
| <td>A file.</td> |
| </tr> |
| <tr class="a"> |
| <td><a href="appenders/daily-file.html">LoggerAppenderDailyFile</a></td> |
| <td>A file (new file each day).</td> |
| </tr> |
| <tr class="b"> |
| <td><a href="appenders/rolling-file.html">LoggerAppenderRollingFile</a></td> |
| <td>A file (new file when a specified size has been reached). </td> |
| </tr> |
| <tr class="a"> |
| <td><a href="appenders/mail.html">LoggerAppenderMail</a></td> |
| <td>Sends the log via email. The entire log is sent in one email.</td> |
| </tr> |
| <tr class="b"> |
| <td><a href="appenders/mail-event.html">LoggerAppenderMailEvent</a></td> |
| <td>Sends the log via email. Each log entry is sent in individual emails.</td> |
| </tr> |
| <tr class="a"> |
| <td><a href="appenders/mongodb.html">LoggerAppenderMongoDB</a></td> |
| <td>MongoDB.</td> |
| </tr> |
| <tr class="b"> |
| <td><a href="appenders/null.html">LoggerAppenderNull</a></td> |
| <td>Ignores all log events.</td> |
| </tr> |
| <tr class="a"> |
| <td><a href="appenders/pdo.html">LoggerAppenderPDO</a></td> |
| <td>Database.</td> |
| </tr> |
| <tr class="b"> |
| <td><a href="appenders/php.html">LoggerAppenderPhp</a></td> |
| <td>Creates a PHP user-level message using the PHP <tt>trigger_error()</tt> function.</td> |
| </tr> |
| <tr class="a"> |
| <td><a href="appenders/socket.html">LoggerAppenderSocket</a></td> |
| <td>A network socket.</td> |
| </tr> |
| <tr class="b"> |
| <td><a href="appenders/syslog.html">LoggerAppenderSyslog</a></td> |
| <td>Syslog.</td> |
| </tr> |
| |
| </tbody> |
| </table> |
| |
| </div> |
| |
| |
| <a name="Configuring_appenders"></a><div class="section"><h3 id="Configuring_appenders">Configuring appenders</h3> |
| |
| <p>The following configuration shows how to configure an appender which logs to a file:</p> |
| |
| <div class="prettyprint linenums"><pre> |
| <configuration xmlns="http://logging.apache.org/log4php/"> |
| <appender name="default" class="LoggerAppenderFile"> |
| <layout class="LoggerLayoutTTCC" /> |
| <param name="file" value="/var/log/my.log" /> |
| <param name="append" value="true" /> |
| </appender> |
| <root> |
| <appender_ref ref="default" /> |
| </root> |
| </configuration> |
| </pre></div> |
| |
| <p>From the configuration you can see that an appender has the following properties:</p> |
| |
| <ul> |
| <li>A <b>name</b> which uniquely identifies it, in this case <i>default</i>.</li> |
| <li>A <b>class</b> which specifies which appender class will be used to handle the |
| requests. Since we wish to log to a file, <tt>LoggerAppenderFile</tt> is used in this case.</li> |
| <li>A <b>layout</b> which transforms the logging events to string which can be logged. |
| A layout is required by most appenders, but some do not require it, such as the database appender. |
| If a layout is not defined, the appenders will use a default layout.</li> |
| <li>Zero or more <b>parameters</b> which configure the appender |
| behaviour. In this example, the <i>file</i> parameter governs the path to the file which will be |
| used for logging, and <i>append</i> defines that log messages should be appended to the file, |
| instead of truncating it.</li> |
| </ul> |
| |
| </div> |
| |
| <div class="section"><h3>Linking appenders to loggers<a name="Linking_appenders_to_loggers"></a></h3> |
| |
| <p>A logger can be linked to one or more appenders. Also, multiple loggers can share the same |
| appender.</p> |
| |
| <p>Consider the following configuration:</p> |
| |
| <div class="prettyprint linenums"><pre> |
| <log4php:configuration xmlns:log4php="http://logging.apache.org/log4php/"> |
| <appender name="primus" class="LoggerAppenderConsole" /> |
| <appender name="secundus" class="LoggerAppenderFile"> |
| <param name="file" value="/var/log/my.log" /> |
| </appender> |
| <logger name="main"> |
| <appender_ref ref="primus" /> |
| <appender_ref ref="secundus" /> |
| </logger> |
| <logger name="alternative"> |
| <appender_ref ref="primus" /> |
| </logger> |
| </log4php:configuration> |
| </pre></div> |
| |
| <p>This configures two appenders, called <i>primus</i> and <i>secundus</i>, and two loggers named |
| <i>main</i> and <i>alternative</i>. The logger <i>main</i> is linked to <i>primus</i> and |
| <i>secundus</i> and will therefore forward logging events to both of them. In other words, |
| it will log both to console and to a file. Logger <i>alternative</i> is only linked to appender |
| <i>primus</i> and will therefore only log to the console.</p> |
| |
| </div> |
| |
| |
| <div class="section"><h3>Appender threshold<a name="Appender_threshold"></a></h3> |
| |
| <p>An appender can be assigned a threshold level. All logging requests with level lower than this threshold |
| will be ignored.</p> |
| |
| <p>For example, if you set <tt>WARN</tt> as a threshold, then <tt>INFO</tt>, <tt>DEBUG</tt> |
| and <tt>TRACE</tt> level events recieved by the appender will not be logged, but <tt>WARN</tt>, |
| <tt>ERROR</tt> and <tt>FATAL</tt> will.</p> |
| |
| <p>An example of setting an appender threshold:</p> |
| |
| <div class="prettyprint linenums"><pre> |
| <configuration xmlns="http://logging.apache.org/log4php/"> |
| <appender name="default" class="LoggerAppenderEcho" threshold="WARN" /> |
| <root> |
| <appender_ref ref="default" /> |
| </root> |
| </configuration> |
| </pre></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> |
| </div> |
| </body> |
| </html> |