Log.class.php 891 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <?php
  2. class Log {
  3. public function Log(){
  4. }
  5. /**
  6. * 记录业务相关的日志 统一格式
  7. */
  8. public static function save_run_log($info,$file_pre_name="") {
  9. if(empty($file_pre_name)){
  10. $file_name = date("Ymd").".log";
  11. }else{
  12. $file_name = $file_pre_name."_".date("Ymd").".log";
  13. }
  14. Log::write_log($info,$file_name);
  15. }
  16. /**
  17. * 记录系统出错的日志
  18. */
  19. public static function save_err_log($info) {
  20. $file_name = "error_".date("Ymd").".log";
  21. Log::write_log($info,$file_name);
  22. }
  23. /**
  24. * 将日志信息写入到文本文件
  25. */
  26. private static function write_log($info,$file_name) {
  27. $path = LOG_DIR;
  28. if(file_exists($path) == false) {
  29. mkdir($path);
  30. chmod($path,0777);
  31. }
  32. $fp = fopen("$path/$file_name","a");
  33. $log = "[".date("Y-m-d H:i:s")."]|".$info."\r\n";
  34. fwrite($fp,$log);
  35. fclose($fp);
  36. }
  37. }
  38. ?>