Home >php教程 >PHP源码 >一个安全的快速写日志的函数

一个安全的快速写日志的函数

PHP中文网
PHP中文网Original
2016-05-25 17:08:291421browse

php代码

<?php

/**
 * 直接记录日志
 * @param$lvevel
 * @param string $level
 *  http://www.phpqee.com
 */
function Write($msg, $level) {
    $arr_level = explode(&#39;,&#39;, YUC_LOG_TYPE);
    if (in_array($level, $arr_level)) {
        $record = date(&#39;Y-m-d H:m:s&#39;) . " >>> " . number_format(microtime(TRUE), 5, ".", "") . &#39; &#39; . " : " . $level . "\t" . $msg;
        $base = M_PRO_DIR . "/Log";
        $dest = $base . "/" . date("YmdH", time()) . &#39;log.php&#39;;
        if (!file_exists($dest)) {
            @mkdir($base, 0777, TRUE);
            @file_put_contents($dest, "\r\n", FILE_APPEND);
        }
        if (file_exists($dest)) {
            @file_put_contents($dest, $record . "\r\n", FILE_APPEND);
        }
    }
}

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:ci框架 省市三级联动Next article:在线短地址服务