log.php 1.6 KB

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