Sae.class.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. protected $config = array(
  14. 'log_time_format' => ' c ',
  15. );
  16. // 实例化并传入参数
  17. public function __construct($config=array()){
  18. $this->config = array_merge($this->config,$config);
  19. }
  20. /**
  21. * 日志写入接口
  22. * @access public
  23. * @param string $log 日志信息
  24. * @param string $destination 写入目标
  25. * @return void
  26. */
  27. public function write($log,$destination='') {
  28. static $is_debug=null;
  29. $now = date($this->config['log_time_format']);
  30. $logstr="[{$now}] ".$_SERVER['REMOTE_ADDR'].' '.$_SERVER['REQUEST_URI']."\r\n{$log}\r\n";
  31. if(is_null($is_debug)){
  32. preg_replace('@(\w+)\=([^;]*)@e', '$appSettings[\'\\1\']="\\2";', $_SERVER['HTTP_APPCOOKIE']);
  33. $is_debug = in_array($_SERVER['HTTP_APPVERSION'], explode(',', $appSettings['debug'])) ? true : false;
  34. }
  35. if($is_debug)
  36. sae_set_display_errors(false);//记录日志不将日志打印出来
  37. sae_debug($logstr);
  38. if($is_debug)
  39. sae_set_display_errors(true);
  40. }
  41. }