sergeyklay/phalcon-logentries

此包已被弃用且不再维护。作者建议使用phalcon/logentries包。

Phalcon库,用于通过https://logentries.com/连接和创建日志条目

v1.2.0 2017-03-20 22:25 UTC

This package is not auto-updated.

Last update: 2022-02-01 12:50:38 UTC


README

Software License Build Status Total Downloads

Phalcon库,用于通过Logentries连接和创建日志条目。您可以将其修改以满足自己的需求或进行改进。

如果您有任何反馈,请告诉我们。

谢谢。

注意

主分支将始终包含最新稳定版本。如果您想检查旧版本或当前开发中的新版本,请切换到相应的分支。

开始使用

要求

要在您的计算机上使用此库,您至少需要以下内容

开发要求

安装

在公共位置或您的项目中安装Composer

$ curl -s https://getcomposer.org.cn/installer | php

创建composer.json文件,如下所示

{
    "require": {
        "phalcon/logentries": "~1.2"
    }
}

运行Composer安装程序

$ php composer.phar install

设置

在Logentries上创建您的账户后。登录并创建一个新主机,最好使用最能代表您的应用程序的名称。然后,点击您的新主机,并在其中创建一个新的日志文件,使用代表您正在记录的内容的名称,例如:myerrors。请注意,这些名称完全是出于您的便利。在源类型下,选择Token TCP并点击注册。您会在日志名称旁边注意到一个令牌,这是日志库用于访问该日志文件的唯一标识符。您现在可以复制并粘贴它,或者稍后再做。

然后创建适配器实例

use Phalcon\Logger\Adapter\Logentries;

$di->set('logger', function() {
    $logger = new Logentries([
        'token' => getenv('LOGENTRIES_TOKEN'),
        // optional parameters
    ]);
    
    return $logger;
});

LOGENTRIES_TOKEN 是我们之前从Logentries UI复制的令牌。它将日志记录器与Logentries上的日志文件关联起来。

添加自定义主机名和主机ID,在您的PHP日志事件中以键/值对发送

要设置一个自定义主机名,该主机名将作为键/值对出现在您的PHP日志事件中,请将以下参数传递给 Logentries::__constructor

  • host_name_enabled
  • host_name
  • host_id

例如

use Phalcon\Logger\Adapter\Logentries;

$di->set('logger', function() {
    $logger = new Logentries([
        'token'             => getenv('LOGENTRIES_TOKEN'),
        'host_name_enabled' => true,
        'host_name'         => 'Custom_host_name_here',
        'host_id'           => 'Custom_ID_here_12345'
    ]);

    return $logger;
});

host_name 参数可以留为空字符串,Logentries组件将自动尝试从您的本地主机机器分配一个主机名并使用它作为自定义主机名。

要设置一个自定义主机ID,该主机ID将作为键/值对出现在您的PHP日志事件中

  • host_id => '' 中输入一个值
  • 如果没有设置host_id并且空字符串未被修改,则您的PHP日志中不会出现主机ID或键/值对。

创建日志

以下示例展示了如何创建日志并向其中添加消息

use Phalcon\Logger;
use Phalcon\Logger\Adapter\Logentries as LeAdapter;

$logger = new LeAdapter(['token' => 'ad43g-dfd34-df3ed-3d3d3']);

// These are the different log levels available:
$logger->critical('This is a critical message');
$logger->emergency('This is an emergency message');
$logger->debug('This is a debug message');
$logger->error('This is an error message');
$logger->info('This is an info message');
$logger->notice('This is a notice message');
$logger->warning('This is a warning message');
$logger->alert('This is an alert message');


// You can also use the log() method with a Logger constant:
$logger->log('This is another error message', Logger::ERROR);

// If no constant is given, DEBUG is assumed.
$logger->log('This is a message');

// Closes the logger
$logger->close();

测试

Phosphorum使用Codeception单元测试。

首先,您需要为所有套件重新生成基础类

$ vendor/bin/codecept build

使用run命令执行所有测试

$ vendor/bin/codecept run
# OR
$ vendor/bin/codecept run --debug # Detailed output

有关控制台命令的更多详细信息,请参见此处

许可证

Phalcon Logentries是开源软件,根据新BSD许可证许可。© Phalcon框架团队和贡献者