示例#1
0
 /**
  * 构造函数
  * @param $data
  * @param bool $encode
  */
 public function __construct($data, $encode = true)
 {
     $data = TXString::recursionEncode($data, $encode);
     if (SYS_CONSOLE && TXLogger::$ConsoleOut) {
         TXLogger::format();
         $data['__logs'] = TXLogger::$ConsoleOut;
         TXLogger::$ConsoleOut = array();
     }
     $this->data = $data;
 }
示例#2
0
 /**
  * 返回所有日志
  */
 public static function showLogs()
 {
     if (self::$ConsoleOut) {
         self::format();
         if (RUN_SHELL) {
             foreach (self::$ConsoleOut as $Out) {
                 $value = $Out['value'];
                 $key = $Out['key'];
                 $type = $Out['type'];
                 if (is_array($value)) {
                     $value = var_export($value, true);
                 }
                 echo "[{$type}] {$key} => {$value}\n";
             }
         } elseif (SYS_CONSOLE) {
             echo "\n<script type=\"text/javascript\">\n";
             foreach (self::$ConsoleOut as $Out) {
                 $value = $Out['value'];
                 $key = $Out['key'];
                 $type = $Out['type'];
                 if (is_array($value)) {
                     $value = json_encode($value);
                     $message = sprintf('console.%s("%s => ", %s);', $type, $key, $value ?: "false");
                 } else {
                     $message = sprintf('console.%s("%s => ", "%s");', $type, $key, addslashes(str_replace(array("\r\n", "\r", "\n"), "", $value)));
                 }
                 echo $message . "\n";
             }
             echo "</script>";
         }
         self::$ConsoleOut = array();
     }
 }