php写日志

在php中经常需要用到写日志来看结果的时候,下面方法就是记录写日志

<?php

function setTrace($trace, $fname = 'trace_exception', $pathName = 'exception')
{
    $path = app()->getRootPath() . '/public/' . $pathName . '/' . date('Ymd');
    if (!is_dir($path)) mkdir($path, 0775, true);
    $file = $path . '/' . $fname . '.txt';


    @file_put_contents($file, date('Y-m-d H:i:s') . ' ' . $fname . ':start---------------------------------------' . "\r\n", FILE_APPEND);
    foreach ($trace as $t) {
        @file_put_contents($file, json_encode($t) . "\r\n", FILE_APPEND);
    }
    @file_put_contents($file, date('Y-m-d H:i:s') . ' ' . $fname . ':end---------------------------------------' . "\r\n", FILE_APPEND);
}
?>
标签:

相关文章

发表评论