codeless/logmore

提供 openlog、closelog 和 syslog 函数包装器的极简日志工具

v0.9.0 2012-10-12 12:08 UTC

This package is not auto-updated.

Last update: 2023-09-16 08:13:13 UTC


README

LogMore 类是一个针对 PHP 5.2 及以上版本的极简 PHP 日志工具,它为 openlog、closelog 和 syslog 函数提供了包装器。

PHP 内使用示例

require('vendor/codeless/logmore/src/logmore.php');

# Opening of the log is not required, but recommended.
# Here you can pass an ident-string of your application,
# which makes filtering of the messages easier later on:
LogMore::open('nameOfApplication');

# Possible priorities for messages:
LogMore::emerg('a emergency message');
LogMore::alert('an alert message');
LogMore::crit('a critical message');
LogMore::err('an error message');
LogMore::warning('a warning');
LogMore::notice('a notice');
LogMore::info('a informative message');
LogMore::debug('a debug message');

# All messages are formated via (vs)printf,
# so the following is possible:
LogMore::debug('Variable $test is of type %s', gettype($test));

# The number of arguments to the logging functions
# is not restricted by LogMore:
LogMore::notice(
	'Message string coming from file %s at line %i ...',
	__FILE__,
	__LINE__,
	...);

# Disable logging:
LogMore::disable();
# Won't land in the logfile:
LogMore::debug('A debug message');

# Enable logging:
LogMore::enable();
# Will land in the logfile again:
LogMore::debug('Another debug message');

使用 LogMore 与 Unix/Linux tail 命令配合工作得很好。在开发过程中,通过在 shell 中输入以下命令来捕获日志文件的追加部分:

/usr/bin/tail -F /path/to/error.log

多日志

LogMore 阻止使用具有不同标识符的多个日志。在调用 LogMore::open 并传入标识符 "x" 之后,如果未在之间调用 close(),则 LogMore 将忽略对 open() 的任何其他调用。

LogMore::open('ident1');
LogMore::open('ident2');
LogMore::debug('A message'); # Still logging with ident1!

LogMore::close(); # Closing ident1
LogMore::open('ident2');
LogMore::debug('A message'); # Logging with ident2!

安装

可以通过下载 src/logmore.php 文件或使用 packagist/composer(见资源部分)来安装 LogMore。

编译

LogMore 已经“编译”好,可以直接用于您的 PHP 应用程序。如果您想修改 LogMore,请查看附带的 Makefile。

文档

默认情况下不包含文档,但可以使用 Natural Docs 编译。当您安装了 Natural Docs 时,只需在 LogMore 的根目录中输入以下命令:

make doc

即可。

资源

改进 LogMore 的想法

  • 启用/禁用单个优先级的日志记录以减少 syslog() 调用

致谢和错误报告

LogMore 由 Codeless 编写(http://www.codeless.at/)。所有错误报告都可以发送到 more@codeless.at -- 更好的错误报告可以发布在此包的 github 存储库中:https://www.github.com/codeless/logmore

许可证

此作品根据 Creative Commons Attribution 3.0 Unported 许可证授权:http://creativecommons.org/licenses/by/3.0/deed.en_US