log.php 992 B

12345678910111213141516171819202122232425262728293031
  1. <?php
  2. /**
  3. * 记录日志
  4. ***/
  5. defined('InShopNC') or exit('Access Invalid!');
  6. class Log{
  7. const SQL = 'SQL';
  8. const ERR = 'ERR';
  9. private static $log = array();
  10. public static function record($message,$level=self::ERR) {
  11. $now = @date('Y-m-d H:i:s',time());
  12. switch ($level) {
  13. case self::SQL:
  14. self::$log[] = "[{$now}] {$level}: {$message}\r\n";
  15. break;
  16. case self::ERR:
  17. $log_file = BASE_DATA_PATH.'/log/'.date('Ymd',TIMESTAMP).'.log';
  18. $url = $_SERVER['REQUEST_URI'] ? $_SERVER['REQUEST_URI'] : $_SERVER['PHP_SELF'];
  19. $url .= " ( act={$_GET['act']}&op={$_GET['op']} ) ";
  20. $content = "[{$now}] {$url}\r\n{$level}: {$message}\r\n";
  21. file_put_contents($log_file,$content, FILE_APPEND);
  22. break;
  23. }
  24. }
  25. public static function read(){
  26. return self::$log;
  27. }
  28. }