PhpRiot
Become Zend Certified

Prepare for the ZCE exam using our quizzes (web or iPad/iPhone). More info...


When you're ready get 7.5% off your exam voucher using voucher CJQNOV23 at the Zend Store

Simple Formatting

Zend_Log_Formatter_Simple is the default formatter. It is configured automatically when you specify no formatter. The default configuration is equivalent to the following:

<?php
$format 
'%timestamp% %priorityName% (%priority%): %message%' PHP_EOL;
$formatter = new Zend_Log_Formatter_Simple($format);

A formatter is set on an individual Writer object using the Writer's setFormatter() method:

<?php
$writer 
= new Zend_Log_Writer_Stream('php://output');
$formatter = new Zend_Log_Formatter_Simple('hello %message%' PHP_EOL);
$writer->setFormatter($formatter);

$logger = new Zend_Log();
$logger->addWriter($writer);

$logger->info('there');

// outputs "hello there"

The constructor of Zend_Log_Formatter_Simple accepts a single parameter: the format string. This string contains keys surrounded by percent signs (e.g. %message%). The format string may contain any key from the event data array. You can retrieve the default keys by using the DEFAULT_FORMAT constant from Zend_Log_Formatter_Simple.

Zend Framework