Filtering is a mechanism to configure enhanced logging. For example, filter enable you to log debug statements into the one appender and info into the other. Or, if you want to log only certain statements with a defined regex into one specified file, this can also be done with filters.
Currently filters are only enabled for the XML configuration.If you need complex features, than you better go with XML instead of property files.
Here is an configuration example:
<log4php:configuration xmlns:log4php="http://logging.apache.org/log4php/" threshold="WARN">
<appender threshold="INFO" name="blub" class="LoggerAppenderEcho">
<layout class="LoggerLayoutSimple"/>
<filter class="LoggerFilterLevelRange">
<param name="LevelMin" value="debug" />
<param name="LevelMax" value="debug" />
</filter>
<filter class="LoggerFilterDenyAll" />
</appender>
<root>
<level value="WARN" />
<appender_ref ref="blub" />
</root>
</log4php:configuration>
This confiuration adds two filters to the appender. One is the LevelRange appender. As you can see, there are more than one filters possible. Log4PHP builds up a so called filter chain. That means, that after the LevelRange filter, the DenyAll-Filter is beeing processed.
As the names are suggesting, this configuration would enable logging for the debug level only. All other messages will be denied.
This filters simply denies all logging events.
This filter accepts the specified logger level or denys it.
| LevelToMatch | The level to match |
| AcceptOnMatch | If true, the matching log level is accepted, denied otherwise |
Example:
<filter class="LoggerFilterLevelMatch">
<param name="LevelToMatch" value="debug" />
<param name="AcceptOnMatch" value="true" />
</filter>
This filter logs if the LoggerLevel is within the specified range.
| LevelMin | The minimum level to log |
| LevelMax | The maximum level to log |
Example:
<filter class="LoggerFilterLevelRange">
<param name="LevelMin" value="debug" />
<param name="LevelMax" value="debug" />
</filter>
Logs or denies, if the specified string matches (with the strpos function).
| StringToMatch | The string to match |
| AcceptOnMatch | If true, the matching is logged, denied otherwise |
Example:
require_once dirname(__FILE__).'/../../main/php/Logger.php';
Logger::configure(dirname(__FILE__).'/../resources/filter_stringmatch.xml');
$logger = Logger::getRootLogger();
$logger->debug("Some text to match that will be rejected");
$logger->info("Some other text that will be accepted");