log.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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/sql_' . 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. case self::ERR:
  24. $log_file = BASE_DATA_PATH . '/log/' . date('Ymd', TIMESTAMP) . '.log';
  25. $url = $_SERVER['REQUEST_URI'] ? $_SERVER['REQUEST_URI'] : $_SERVER['PHP_SELF'];
  26. $url .= " ( act={$_GET['act']}&op={$_GET['op']} ) ";
  27. $content = "[{$now}] {$url}\r\n{$level}: {$message}\r\n";
  28. file_put_contents($log_file, $content, FILE_APPEND);
  29. break;
  30. }
  31. }
  32. public static function read()
  33. {
  34. return self::$log;
  35. }
  36. }