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

Writing to Streams

Zend_Log_Writer_Stream sends log data to a PHP stream.

To write log data to the PHP output buffer, use the URL php://output. Alternatively, you can send log data directly to a stream like STDERR (php://stderr).

<?php
$writer 
= new Zend_Log_Writer_Stream('php://output');
$logger = new Zend_Log($writer);

$logger->info('Informational message');

To write data to a file, use one of the Filesystem URLs:

<?php
$writer 
= new Zend_Log_Writer_Stream('/path/to/logfile');
$logger = new Zend_Log($writer);

$logger->info('Informational message');

By default, the stream opens in the append mode ("a"). To open it with a different mode, the Zend_Log_Writer_Stream constructor accepts an optional second parameter for the mode.

The constructor of Zend_Log_Writer_Stream also accepts an existing stream resource:

<?php
$stream 
= @fopen('/path/to/logfile''a'false);
if (! 
$stream) {
    throw new 
Exception('Failed to open stream');
}

$writer = new Zend_Log_Writer_Stream($stream);
$logger = new Zend_Log($writer);

$logger->info('Informational message');

You cannot specify the mode for existing stream resources. Doing so causes a Zend_Log_Exception to be thrown.

Zend Framework