Formatters
A Formatter is an object that is responsible for taking an Some Writers are not line-oriented and cannot use a Formatter. An example is the Database Writer, which inserts the event items directly into database columns. For Writers that cannot support a Formatter, an exception is thrown if you attempt to set a Formatter. Simple FormattingZend_Log_Formatter_Simple is the default formatter. It is configured automatically when you specify no formatter. The default configuration is equivalent to the following:
A formatter is set on an individual Writer object using the Writer's setFormatter() method:
The constructor of Zend_Log_Formatter_Simple accepts a single
parameter: the format string. This string contains keys surrounded by
percent signs (e.g. Formatting to XMLZend_Log_Formatter_Xml formats log data into XML strings. By default, it automatically logs all items in the event data array:
The code above outputs the following XML (space added for clarity):
It's possible to customize the root element as well as specify a mapping of XML elements to the items in the event data array. The constructor of Zend_Log_Formatter_Xml accepts a string with the name of the root element as the first parameter and an associative array with the element mapping as the second parameter:
logEntry to log . It also maps the element
msg to the event data item message . This
results in the following output:
|