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

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

PHP中文网
Release: 2016-05-25 17:08:29
Original
1429 people have browsed it

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);
        }
    }
}
Copy after login

Statement of this Website
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
Latest Articles by Author
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template