AppendersLogging requests can be sent to multiple destinations, such as files, databases, syslog and others. Such destinations are called appenders. Appenders are attached to loggers and each logger can have multiple attached appenders. Appender referenceThe following appender classes are available:
Configuring appendersThe following configuration shows how to configure an appender which logs to a file: <configuration xmlns="http://logging.apache.org/log4php/"> <appender name="default" class="LoggerAppenderFile"> <layout class="LoggerLayoutSimple" /> <param name="file" value="/var/log/my.log" /> <param name="append" value="true" /> </appender> <root> <appender_ref ref="default" /> </root> </configuration> From the configuration you can see that an appender has the following properties:
Linking appenders to loggersA logger can be linked to one or more appenders. Also, multiple loggers can share the same appender. Consider the following configuration: <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> This configures two appenders, called primus and secundus, and two loggers named main and alternative. The logger main is linked to primus and secundus and will therefore forward logging events to both of them. In other words, it will log both to console and to a file. Logger alternative is only linked to appender primus and will therefore only log to the console. Appender thresholdAn appender can be assigned a threshold level. All logging requests with level lower than this threshold will be ignored. For example, if you set WARN as a threshold, then INFO, DEBUG and TRACE level events recieved by the appender will not be logged, but WARN, ERROR and FATAL will. An example of setting an appender threshold: <configuration xmlns="http://logging.apache.org/log4php/"> <appender name="default" class="LoggerAppenderEcho" threshold="WARN" /> <root> <appender_ref ref="default" /> </root> </configuration> |