Sae.class.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | TOPThink [ WE CAN DO IT JUST THINK ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2011 http://topthink.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
  8. // +----------------------------------------------------------------------
  9. // | Author: luofei614 <weibo.com/luofei614>
  10. // +----------------------------------------------------------------------
  11. namespace Think\Log\Driver;
  12. class Sae
  13. {
  14. protected $config = array(
  15. 'log_time_format' => ' c ',
  16. );
  17. // 实例化并传入参数
  18. public function __construct($config = array())
  19. {
  20. $this->config = array_merge($this->config, $config);
  21. }
  22. /**
  23. * 日志写入接口
  24. * @access public
  25. * @param string $log 日志信息
  26. * @param string $destination 写入目标
  27. * @return void
  28. */
  29. public function write($log, $destination = '')
  30. {
  31. static $is_debug = null;
  32. $now = date($this->config['log_time_format']);
  33. $logstr = "[{$now}] " . $_SERVER['REMOTE_ADDR'] . ' ' . $_SERVER['REQUEST_URI'] . "\r\n{$log}\r\n";
  34. if (is_null($is_debug)) {
  35. preg_replace('@(\w+)\=([^;]*)@e', '$appSettings[\'\\1\']="\\2";', $_SERVER['HTTP_APPCOOKIE']);
  36. $is_debug = in_array($_SERVER['HTTP_APPVERSION'], explode(',', $appSettings['debug'])) ? true : false;
  37. }
  38. if ($is_debug) {
  39. sae_set_display_errors(false); //记录日志不将日志打印出来
  40. }
  41. sae_debug($logstr);
  42. if ($is_debug) {
  43. sae_set_display_errors(true);
  44. }
  45. }
  46. }