Home  >  Article  >  Backend Development  >  php write log function

php write log function

不言
不言Original
2018-04-14 09:17:242549browse

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;
    }

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!

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