如何使用Zend Log作为一个独立的组件?

发布于 2025-01-02 14:26:12 字数 72 浏览 1 评论 0原文

我想使用 Zend Framwork 的 Log 机制作为一个单独的组件,这意味着我想要从 ZF 得到的只是 Log,我该怎么做?

I want to use Zend Framwork's Log mechanism as a separated component,that means all I want from ZF is just the Log, How can I do this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

彻夜缠绵 2025-01-09 14:26:12

根据这两个页面

Zend_Log 需要 Zend_Exception 和以下

  • DOM
  • libxml
  • Reflection

这意味着您实际上只需要框架本身的以下内容

library/Zend/Exception.php
library/Zend/Log.php
library/Zend/Log <- the directory

然后您应该能够将记录器用作独立组件。只需将上面列表中的 library 文件夹添加到您的包含路径中(Zend Framework 组件依赖于此)

set_include_path(implode(PATH_SEPARATOR, array(
    '/path/to/library',
    get_include_path()
)));

require_once 'Zend/Log/Writer/Stream.php';
require_once 'Zend/Log.php';

$writer = new Zend_Log_Writer_Stream('/path/to/logfile');
$log = new Zend_Log($writer);
$log->log('Some message', 1);

According to these two pages

Zend_Log requires Zend_Exception and the following

  • DOM
  • libxml
  • Reflection

What this means is that you really only need the following from the framework itself

library/Zend/Exception.php
library/Zend/Log.php
library/Zend/Log <- the directory

You should then be able to use the logger as a stand-alone component. Just add the library folder in the list above to your include path (Zend Framework components rely on this)

set_include_path(implode(PATH_SEPARATOR, array(
    '/path/to/library',
    get_include_path()
)));

require_once 'Zend/Log/Writer/Stream.php';
require_once 'Zend/Log.php';

$writer = new Zend_Log_Writer_Stream('/path/to/logfile');
$log = new Zend_Log($writer);
$log->log('Some message', 1);
离不开的别离 2025-01-09 14:26:12

每当我想使用 Zend Framework 中的各个组件时,我只需包含一个名为 zend_setup.php 的小文件,其中包含以下三行代码:

set_include_path( '/Users/me/workspace/proj_name/library' . PATH_SEPARATOR . get_include_path());
require_once( '/Users/me/workspace/proj_name/library/Zend/Loader/Autoloader.php' );
Zend_Loader_Autoloader::getInstance();

这可能不如发出显式 require_once( ) 语句,但我喜欢它提供的便利。例如,您可能很快决定还想使用 Zend_Log_Writer_Firebug()Zend_Log_Writer_Mail()。使用自动加载器可以避免编写所有额外的 require_once() 语句。

Whenever I want to use individual components from Zend Framework I simply include a small file called zend_setup.php that contains the following three lines of code:

set_include_path( '/Users/me/workspace/proj_name/library' . PATH_SEPARATOR . get_include_path());
require_once( '/Users/me/workspace/proj_name/library/Zend/Loader/Autoloader.php' );
Zend_Loader_Autoloader::getInstance();

This is probably not as efficient as issuing explicit require_once() statements, but I like the convenience it offers. For example, you may very quickly decide you also want to utilize Zend_Log_Writer_Firebug() and Zend_Log_Writer_Mail(). Using the autoloader avoids having to write all those additional require_once() statements.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文