Log4Php 运行时属性设置
我有一个 PHP 应用程序,其中包含多个模块以及每个模块内的各种设置。我想使用 log4php 启用日志记录,但每个单独的模块都有不同的设置(即日志级别、日志文件等)。其中一些设置需要由最终用户(日志级别)即时更改,我想将这些属性存储在数据库中。
现在我可以动态设置日志级别。但我无法确定如何动态设置其他属性。有关 log4php 配置的文档几乎完全是通过properties/xml 文件完成的——尽管它说所有设置都可以通过编程方式更改。
有人做过这样的事吗?如果是这样,我该怎么做?我浏览了 http://incubator.apache.org/log4php/index 处的文档。 html,但我需要更多帮助。
澄清一下 - 我不想使用配置文件,因为最终用户无法直接访问这些文件。我将提供一个前端来更改某些日志记录设置,所有设置都将存储在数据库中。
I have a PHP application containing multiple modules and various settings within each module. I'd like to enable logging using log4php, but each individual module has different settings (ie. Log level, log file, etc). Some of these settings need to be changed on the fly by end users (log level), and I'd like to store these properties in the database.
Right now I can set loglevel dynamically. I can not determine how to set other properties dynamically though. Documentation on the configuration of log4php is almost exclusively done via properties/xml files - though it says all settings can be changed programmatically.
Has any done something like this? If so, how do I do so? I've looked through the documentation at http://incubator.apache.org/log4php/index.html, but I need more assistance.
To clarify - I do NOT want to use configuration files, as the end users will not have direct access to these. I will provide a front end to change certain logging settings, and all settings will be stored in the database.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
查看 API 文档告诉我他们正在使用配置适配器和策略模式来配置记录器。适配器有一个方法 configure,由 main 调用记录器。有一个 LoggerConfiguratorPhp,它将读取/包含返回的 PHP 文件一个常规的 PHP 数组。我可以想象这可以很容易地修改为接受从数据库返回的数组。查看此类的源代码作为起点。您需要创建的是一个 LoggerConfiguratorDB,然后您可以将其传递给主 Logger 类,如下所示:
我从未使用过 Log4Php,这只是通过查看 API 进行假设。我完全不知道新适配器会是什么样子。但也许这会让你走向正确的方向。
如果你设法想出一些东西,为什么不将其捐赠给该项目:)
Looking at the API Docs tells me they are using Config Adapters and a Strategy Pattern to configure the loggers. The adapters have a single method configure, which is called by the main Logger. There is a LoggerConfiguratorPhp, which will read/include a PHP file returning a regular PHP array. I could imagine this could easily be modified to accept an array returned from the database instead. Have a look at the source code of this class for starting point. What you will want to create is a
LoggerConfiguratorDB
, which you can then pass to the main Logger class like this:I never worked with Log4Php and this is just assuming by looking at the API. I have absolutely no clue, how the new adapter would have to look like. But maybe this gets you into the right direction.
If you manage to come up with something why not donate it to the project :)