log.php 1.2 KB

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