volador log

v1.0.170116 2017-01-16 08:06 UTC

This package is not auto-updated.

Last update: 2024-06-22 18:24:58 UTC


README

Volador2 Log

##依赖:

  • volador2/helpers

说明

####配置日志模版和处理外部数据

<?php

use Volador\Log\Logger;
use Volador\Log\LogConfig;

class Bootstrap
{
    function ___init() {
        LogConfig::logfile("/var/log/a.log");
        LogConfig::template("{DATETIME} [{REQUEST_ID}][{LEVEL}] {FILE}:{LINE} {CONTENT}");

        // 设置日志模版中KEY的值
        LogConfig::setTemplateVal('REQUEST_ID', $REQUEST_ID);
    }
}

####记录日志

use Volador\Log\Logger;
class DemoController
{
    function indexAction()
    {
        Logger::debug('hello, {name}', ['name' => 'Lin{name}']);
    }
}

####常驻进程

use Volador\Log\Logger;
use Volador\Log\LogConfig;

class Daemon
{
    
    function __construct()
    {
        LogConfig::logfile('/path/debug.log');
        LogConfig::template('{DATETIME} [{REQUEST_ID}][{LEVEL}] {FILE}:{LINE} {CONTENT}');
    }

    public function run()
    {
        for (;;) { 
            LogConfig::setTemplateVal('REQUEST_ID', $REQUEST_ID);
            Logger::debug('hello, {name}', ['name' => 'Lin{name}']);

            Logger::fflush();
        }
    }
}

API 函数列表

当出现致命的运行时错误。这类错误一般是不可恢复的情况。后果是导致脚本终止不再继续运行。

Logger::fatal($message, array $context = array())

运行时警告 (非致命错误)。仅给出提示信息,但是脚本不会终止运行。

Logger::warning($message, array $context = array())

表示遇到可能会表现为错误的情况,但是在可以正常运行的脚本里面也可能会有类似的通知。

Logger::notice($message, array $context = array())

用于帮助调试和查找问题。

Logger::debug($message, array $context = array())

立即写盘并释放当前日志文件

Logger::fflush()