makopov/simple-log

syslog 上的简单日志包装器,基于 PSR-3 的松散实现

v1.0.8 2016-03-05 00:33 UTC

This package is not auto-updated.

Last update: 2024-09-14 18:42:13 UTC


README

syslog 上的简单日志包装器

Simple Log 是一个单例类,使得向 syslog 记录日志变得非常简单。

获取对象实例

$oLogger = SLog::getInstance();

配置应用程序名称(可选)。如果未设置,syslog 将显示 'php' 作为应用程序名称。建议在应用程序的引导或初始化时进行设置。

$oLogger->setApplicationName('MyApp');

现在记录日志!使用任意 8 个日志级别之一

$oLogger->emergency('some message');
$oLogger->alert('some message');
$oLogger->critical('some message');
$oLogger->error('some message');
$oLogger->warning('some message');
$oLogger->notice('some message');
$oLogger->info('some message');
$oLogger->debug('some message');

日志消息将出现在 syslog (/var/log/messages) 中。默认情况下,Simple Log 将包含日志记录的文件名和行号。

示例

Foo.php

function foo() {
    $oLogger->warning('something happened');
}

将在 syslog 中显示如下

Feb 26 22:11:47 localhost MyApp: Foo.php:2 - 发生了某事

就是这样!请提交您发现的任何错误。我将在不久的将来添加测试。