Home > Article > Backend Development > php write log function
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!