net_bazzline/component_proxy_logger

PHP 组件代理日志记录器

1.2.0 2013-12-01 22:18 UTC

This package is auto-updated.

Last update: 2024-09-16 20:40:31 UTC


README

此组件提供了一系列增强的代理日志记录工具。

当前稳定版本为 1.2.0

当前主分支的构建状态由Travis CI跟踪: 构建状态

主要思路是使用带有缓冲区的代理来处理一个或多个 PSR-3 日志记录器,以恢复日志文件的自由度和静音。

功能

  • 完全兼容 PSR-3 日志记录器接口
  • 允许您定义何时将日志消息推送到日志记录器
  • 只有当配置的日志级别达到时才记录日志
  • 恢复日志文件的自由度和静音
  • 使用代理日志记录器组件来组合多个日志记录器的管理

许可证

此软件根据 GNU LESSER GENERAL PUBLIC LICENSE 许可。完整的许可证文本包含在此组件包中。

链接

文档

通用术语

PSR-3 日志记录器

以下是一个未完成的可用 PSR3-Logger 组件列表。

使用此组件的原因

普通记录器与触发刷新缓冲记录器的比较

取自示例 向上刷新缓冲触发器与普通记录器

示例 展示了一个处理项目集合的过程。

第一次运行简单地 记录所有信息。这会迅速填满您的日志。

----------------------------------------
Setting trigger to warning
----------------------------------------
First run with normal logger without log level restriction.
----------------------------------------
[1382566548] [debug] [processing id 1]
[1382566548] [info] [collection information and data id: 1]
[1382566548] [debug] [done]
[1382566548] [debug] [processing id 3]
[1382566548] [info] [collection information and data id: 3]
[1382566548] [info] [data can not handled with this process, queueing data to manual processing list]
[1382566548] [debug] [done]
[1382566548] [debug] [processing id 8]
[1382566548] [info] [collection information and data id: 8]
[1382566548] [info] [logical problem in data on key 3]
[1382566548] [notice] [trying to recalculate data]
[1382566548] [info] [setting data value of key 7 to default]
[1382566548] [debug] [finished]
[1382566548] [debug] [processing id 4]
[1382566548] [info] [collection information and data id: 4]
[1382566548] [debug] [done]
[1382566548] [debug] [processing id 5]
[1382566548] [info] [collection information and data id: 5]
[1382566548] [info] [logical problem in data on key 6]
[1382566548] [notice] [trying to recalculate data]
[1382566548] [warning] [setting data value of key 7 to default not possible]
[1382566548] [notice] [trying to revert modification]
[1382566548] [error] [runtime data and data in storage differs, can not revert modification]
[1382566548] [critical] [lost connection to storage]
[1382566548] [alert] [can not unlock and schedule processing to id 5]
[1382566548] [debug] [done]
[1382566548] [debug] [processing id 6]
[1382566548] [critical] [lost connection to storage]
[1382566548] [alert] [can not unlock and schedule processing to id 6]
[1382566548] [debug] [done]

由于第二次运行有一个仅显示警告及以上日志级别的记录器,因此您不会用不必要的日志请求填满日志。

但很糟糕,当发生某些事情时 您会丢失信息

----------------------------------------
Second run with normal logger and log level restriction to warning and above.
----------------------------------------
[1382566548] [warning] [setting data value of key 7 to default not possible]
[1382566548] [error] [runtime data and data in storage differs, can not revert modification]
[1382566548] [critical] [lost connection to storage]
[1382566548] [alert] [can not unlock and schedule processing to id 5]
[1382566548] [critical] [lost connection to storage]
[1382566548] [alert] [can not unlock and schedule processing to id 6]

第三次运行在不限制的情况下记录一切,仅当发生某些事情时。

不会丢失信息,并且 不会用不必要的日志请求填满日志

----------------------------------------
Third run with manipulate buffer logger.
----------------------------------------
[1382566548] [debug] [processing id 5]
[1382566548] [info] [collection information and data id: 5]
[1382566548] [info] [logical problem in data on key 6]
[1382566548] [notice] [trying to recalculate data]
[1382566548] [warning] [setting data value of key 7 to default not possible]
[1382566548] [notice] [trying to revert modification]
[1382566548] [error] [runtime data and data in storage differs, can not revert modification]
[1382566548] [critical] [lost connection to storage]
[1382566548] [alert] [can not unlock and schedule processing to id 5]
[1382566548] [debug] [processing id 6]
[1382566548] [critical] [lost connection to storage]
[1382566548] [alert] [can not unlock and schedule processing to id 6]

正如您所看到的,只有第三次运行记录了您调试代码和修复可能错误所需的所有信息。

将两个触发刷新缓冲记录器作为单个缓冲记录器中的集合使用

示例 展示了如何将两个触发刷新缓冲记录器作为一个集合使用。

示例使用两个注入到缓冲记录器中的操作缓冲记录器。第一个操作缓冲记录器通过在 alert 日志级别上触发来刷新缓冲区。第二个在 critical 日志级别上触发缓冲区刷新。

此外,示例中模拟了三次运行。第一次运行只添加低于关键或警告级别的日志级别,这意味着不会触发缓冲区刷新。

----------------------------------------
First run - adding info and error messages
----------------------------------------
cleaning log buffer

第二次运行添加的日志级别达到关键级别,这意味着触发了第一个日志记录器的缓冲区刷新。

----------------------------------------
Second run - adding info, error and critical messages

[1382643874] [info] [mail] [Current line is 94]
[1382643874] [error] [mail] [Current line is 95]
[1382643874] [info] [mail] [Current line is 96]
[1382643874] [info] [mail] [Current line is 103]
[1382643874] [error] [mail] [Current line is 104]
[1382643874] [critical] [mail] [Current line is 105]
----------------------------------------
cleaning log buffer

最后,第三次运行添加的日志级别达到警告级别,这意味着触发了两个日志记录器的缓冲区刷新。

----------------------------------------
Third run - adding info, error, critical and alert messages

[1382643874] [info] [mail] [Current line is 106]
[1382643874] [info] [mail] [Current line is 113]
[1382643874] [error] [mail] [Current line is 114]
[1382643874] [critical] [mail] [Current line is 115]
[1382643874] [info] [mail] [Current line is 116]
[1382643874] [alert] [mail] [Current line is 117]
[1382643874] [info] [wakeup call] [Current line is 94]
[1382643874] [error] [wakeup call] [Current line is 95]
[1382643874] [info] [wakeup call] [Current line is 96]
[1382643874] [info] [wakeup call] [Current line is 103]
[1382643874] [error] [wakeup call] [Current line is 104]
[1382643874] [critical] [wakeup call] [Current line is 105]
[1382643874] [info] [wakeup call] [Current line is 106]
[1382643874] [info] [wakeup call] [Current line is 113]
[1382643874] [error] [wakeup call] [Current line is 114]
[1382643874] [critical] [wakeup call] [Current line is 115]
[1382643874] [info] [wakeup call] [Current line is 116]
[1382643874] [alert] [wakeup call] [Current line is 117]
----------------------------------------

这个示例是关于什么的?正如日志请求的名称所预示的,您可以通过在达到关键日志级别时发送电子邮件,以及在达到警告日志级别时发送唤醒电话来实现这一点。