You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

57 lines
1.5 KiB

  1. <?php
  2. namespace backend\modules\hotel\models\Ali;
  3. class TopLogger
  4. {
  5. public $conf = array(
  6. "separator" => "\t",
  7. "log_file" => ""
  8. );
  9. private $fileHandle;
  10. protected function getFileHandle()
  11. {
  12. if (null === $this->fileHandle) {
  13. if (empty($this->conf["log_file"])) {
  14. trigger_error("no log file spcified.");
  15. }
  16. $logDir = dirname($this->conf["log_file"]);
  17. if (!is_dir($logDir)) {
  18. mkdir($logDir, 0777, true);
  19. }
  20. $this->fileHandle = fopen($this->conf["log_file"], "a");
  21. }
  22. return $this->fileHandle;
  23. }
  24. /**
  25. * Author:Steven
  26. * Desc:
  27. * @param $logData //日志内容
  28. * @param $type_name //日志类型 ali/error、ali/order、ali/room_status
  29. * @return bool
  30. */
  31. public function log($logData, $type_name = 'ali/error')
  32. {
  33. if (defined('APP_MODULES_PATH')) {
  34. $file = APP_MODULES_PATH . '/runtime/log/';
  35. } else {
  36. $file = APP_PATH . '/runtime/log/';
  37. }
  38. $file = $file . $type_name . '/';
  39. $this->conf["log_file"] = $file . date('Ymd') . '.log';
  40. if ("" == $logData || array() == $logData) {
  41. return false;
  42. }
  43. if (is_array($logData)) {
  44. $logData = implode($this->conf["separator"], $logData);
  45. }
  46. $logData = $logData . "\n";
  47. fwrite($this->getFileHandle(), $logData);
  48. }
  49. }
  50. ?>