logvice/phplogger

将您的日志发送到LogVice.com网络服务、您的个人LogVice安装或本地文件。

0.1.4 2017-01-12 22:19 UTC

This package is not auto-updated.

Last update: 2024-09-14 18:20:34 UTC


README

Build Status Coverage Status Total Downloads Software License

LogVice\PHPLogger将您的日志发送到LogVice.com服务或您的自建LogVice平台安装。此库实现了PSR-3标准。

安装

安装最新版本

composer require logvice/phplogger

基本用法

<?php

use LogVice\PHPLogger\Logger;
use LogVice\PHPLogger\Config;
use LogVice\PHPLogger\Output\TCPOutput;
use LogVice\PHPLogger\Output\UDPOutput;

// create a config instance
$config = new Config();
$config->setAppKey('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx');
$config->setEnvironment('dev');
$config->setChannel('php');
$config->activateBacktrace();
$config->setOutputHandlers([
    new TCPOutput('127.0.0.1', '8080'),
    new UDPOutput('127.0.0.1', '514'),
]);
$config->setLogLevel(Logger::DEBUG);

// create a log instance
$log = new Logger($config);

// add records to the log
$log->debug('foo');
$log->info('bar');
$log->notice('foo');
$log->warning('bar');
$log->error('foo');
$log->critical('bar');
$log->alert('foo');
$log->emergency('bar');
$log->log(Logger::ERROR, 'foo');

注册错误、异常和关闭处理器

set_error_handler(function ($errno, $errstr, $errfile, $errline) {
    // create a config instance
    $config = new LogVice\PHPLogger\Config();
    $config->setAppKey('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx');
    $config->setEnvironment('dev');
    $config->setChannel('php');
    $config->setOutputHandlers([
        new LogVice\PHPLogger\Output\TCPOutput('127.0.0.1', '8080'),
        new LogVice\PHPLogger\Output\UDPOutput('127.0.0.1', '514'),
        new LogVice\PHPLogger\Output\FileOutput('path/to/logs', 'file-name', true)
    ]);
    $config->setLogLevel(Logger::ERROR);

    // create a log instance
    $logger = new LogVice\PHPLogger\Logger($config);

    $logger->handleError($errno, $errstr, $errfile, $errline);
});

set_exception_handler(function ($exception) {
    // create a config instance
    $config = new LogVice\PHPLogger\Config();
    $config->setAppKey('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx');
    $config->setEnvironment('dev');
    $config->setChannel('php');
    $config->setOutputHandlers([
        new LogVice\PHPLogger\Output\TCPOutput('127.0.0.1', '8080'),
        new LogVice\PHPLogger\Output\UDPOutput('127.0.0.1', '514'),
        new LogVice\PHPLogger\Output\FileOutput('path/to/logs', 'file-name', true)
    ]);
    $config->setLogLevel(Logger::ERROR);

    // create a log instance
    $logger = new LogVice\PHPLogger\Logger($config);

    $logger->handleException($exception);
});

register_shutdown_function(function () {
    // create a config instance
    $config = new LogVice\PHPLogger\Config();
    $config->setAppKey('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx');
    $config->setEnvironment('dev');
    $config->setChannel('php');
    $config->setOutputHandlers([
        new LogVice\PHPLogger\Output\TCPOutput('127.0.0.1', '8080'),
        new LogVice\PHPLogger\Output\UDPOutput('127.0.0.1', '514'),
        new LogVice\PHPLogger\Output\FileOutput('path/to/logs', 'file-name', true)
    ]);
    $config->setLogLevel(Logger::ERROR);

    // create a log instance
    $logger = new LogVice\PHPLogger\Logger($config);

    $logger->handleShutdownError();
});

关于

需求

  • PHPLogger支持PHP 5.4或更高版本。

提交bug和功能请求

bug和功能请求请使用GitHub

作者

Alban Kora - [email protected] - http://twitter.com/albankora

许可证

PHPLogger遵循MIT许可证 - 请参阅LICENSE文件以获取详细信息