Asf_Log_Adapter_File


Introduction

Asf_Log_Adapter_File 文件日志类

Asf框架会自动关闭所有已打开的文件句柄

Asf > 2.2.2, 综合考虑取消了logFormatter类, 框架提供了个性化日志格式函数($this->doLog, $this->log)

在开启命名空间情况下(asf.use_namespace=1)类名为 Asf\Log\Adapter\File

Class synopsis

<?php
final class Asf_Log_Adapter_File extends Asf_Log_AbstractLogger
{
    /* 如果file_path为空, 则寻找asf.log_path, 都不存在抛出错误 */
    public object __construct(string $file_name, string $file_path = '')
    public bool doLog(string $message)
    public bool close()
}

Examples

Example #1 自定义日志目录 LOG_PATH

<?php
define('LOG_PATH', '/data/logs/');
$logger = new Asf_Log_Adapter_File('biz-dd_log', LOG_PATH);

var_dump($logger->info('xxxxx'));

Example #2 默认日志目录 asf.log_path

class IndexService
{
    public function indexAction()
    {
        $logger = new Asf_Log_Adapter_File('biz-dd_log');
        $logger->info(json_encode(array('1', 'a', 'm2' => md5(time()))));
    }
}

$configs = array(
    'asf' => array(
        'root_path'  => '/data/www/',
        'log_path'   => '/data/logs/'
    )
);