Home > Backend Development > PHP Tutorial > php write log function

php write log function

不言
Release: 2023-03-23 19:16:02
Original
2595 people have browsed it

The content of this article is about php writing log function. Now I share it with everyone. Friends in need can refer to it

    public static function log($var, $file = ''){
        $file = LOG_PATH . 'static' . '/' . 'log' . '/' .
        ($file ? $file . '_' : $file) . date('Ymd') . '.log';
        $str = self::encodeObject($var);
        error_log(DTF . ' ' . $str . "\n", 3, $file);
    }
    
    private static function encodeObject($Object){
        $str = '';
        if (is_resource($Object) || is_object($Object)) {
            $str = '** '.(string)$Object.' **';
        } elseif (is_array($Object)) {
            foreach ($Object as $key => $val) {
                $str .= $key . '::::' . self::encodeObject($val) . '\n';
            }
        } else {
            $str = (string)$Object;
        }
        return $str;
    }
Copy after login

Related recommendations:

php writing Input file fwrite() function usage summary

thinkphp write and read cache example

Simple PHP write database class code sharing


The above is the detailed content of php write log function. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template