16.4. Advanced Logging: Multiple Loggers
上一页 | 第 16 章 Zend_Log | 下一页

## 16.4. Advanced Logging: Multiple Loggers

`Zend_Log` supports logging to multiple log adapters. It can either send a message to all logs, or target a message to a specific log.

When creating multiple loggers, each log must be given a unique name. Loggers are registered with the `registerLogger()` method, with the log name supplied as the optional second argument.

In the example below, two loggers are created: one for the console, and one for a file. They will be given the names `Console` and `File`, respectively.

    require_once 'Zend/Log.php';                 // Zend_Log base class
    require_once 'Zend/Log/Adapter/File.php';    // File log adapter
    require_once 'Zend/Log/Adapter/Console.php'; // Console log adapter

    Zend_Log::registerLogger(new Zend_Log_Adapter_File('/logs/framework.txt'), 'File');
    Zend_Log::registerLogger(new Zend_Log_Adapter_Console(), 'Console');

上一页 | 上一级 | 下一页
16.3. Log Levels | 起始页 | 第 17 章 Zend_Mail