예제 #1
0
 /**
  * Format message
  */
 public function formatMessage(Charcoal_LogMessage $msg)
 {
     //        Charcoal_ParamTrait::validateIsA( 1, 'Charcoal_LogMessage', $msg );
     $level = $msg->getLevel();
     $tag = $msg->getTag();
     $message = $msg->getMessage();
     $file = $msg->getFile();
     $line = $msg->getLine();
     $time = date("y/m/d H:i:s");
     // Convert encoding
     $message = $this->convertEncoding(s($message));
     // Get now time
     $now_time = time();
     // set log format string as initial value
     $out = $this->log_format;
     // logging context specific values
     $now_time = time();
     $log_values = array('%Y4%' => date("Y", $now_time), '%Y2%' => date("y", $now_time), '%M2%' => date("m", $now_time), '%M1%' => date("n", $now_time), '%D2%' => date("d", $now_time), '%D1%' => date("j", $now_time), '%H2%' => date("H", $now_time), '%H1%' => date("G", $now_time), '%h2%' => date("h", $now_time), '%h1%' => date("g", $now_time), '%M%' => date("i", $now_time), '%S%' => date("s", $now_time), '%LEVEL%' => $level, '%TAG%' => $tag, '%MESSAGE%' => $message, '%FILE%' => $file, '%FILENAME%' => $file, '%LINE%' => $line);
     // replace keyword
     foreach ($log_values as $key => $value) {
         $out = str_replace($key, $value, us($out));
     }
     // replace environment values
     $out = $this->getSandbox()->getEnvironment()->fill($out);
     return $out;
 }
예제 #2
0
 public function writeln(Charcoal_LogMessage $msg)
 {
     $timestamp = date("Y-m-d H:i:s");
     $level = $msg->getLevel();
     $tag = $msg->getTag();
     $message = $msg->getMessage();
     $file = $msg->getFile();
     $line = $msg->getLine();
     $level_class_def = array("T" => "level_t", "I" => "level_i", "D" => "level_d", "W" => "level_w", "E" => "level_e", "F" => "level_f");
     $td_class = isset($level_class_def[us($level)]) ? $level_class_def[us($level)] : NULL;
     $html = '<tr>' . PHP_EOL;
     $html .= '    <td class="' . $td_class . '"><div class="value center">' . $timestamp . '</div></td>' . PHP_EOL;
     $html .= '    <td class="' . $td_class . '"><div class="value center">' . $level . '</div></td>' . PHP_EOL;
     $html .= '    <td class="' . $td_class . '"><div class="value center">' . $tag . '</div></td>' . PHP_EOL;
     $html .= '    <td class="' . $td_class . '"><div class="value">' . $message . '</div></td>' . PHP_EOL;
     $html .= '    <td class="' . $td_class . '"><div class="value">' . $file . '(' . $line . ')</div></td>' . PHP_EOL;
     $html .= '</tr>' . PHP_EOL;
     echo $html;
 }
예제 #3
0
 public function writeln(Charcoal_LogMessage $msg)
 {
     $req_path = $this->getSandbox()->getEnvironment()->get('%REQUEST_PATH%');
     $req_id = $this->getSandbox()->getEnvironment()->get('%REQUEST_ID%');
     $ip = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '-';
     $level = $msg->getLevel();
     $message = $msg->getMessage();
     $file = $msg->getFile();
     $line = $msg->getLine();
     $time = date("y/m/d H:i:s");
     $file = basename($file);
     // エンコーディング変換
     $message = $this->convertEncoding(s($message));
     // 接続処理
     $this->open();
     // 区切り文字
     $delimiter = ",";
     if (ui($this->_delimiter) == 1) {
         $delimiter = "\t";
     }
     // 改行コード
     $eol = self::CRLF;
     if (ui($this->_eol_code) == 1) {
         $eol = self::CR;
     }
     if (ui($this->_eol_code) == 2) {
         $eol = self::LF;
     }
     // ファイル書き込み
     $orders = uv($this->_field_order);
     $out = "";
     foreach ($orders as $field) {
         $field = strtoupper(trim($field));
         if (strlen($out) > 0) {
             $out .= $delimiter;
         }
         switch ($field) {
             case "%REQUEST_PATH%":
                 $out .= $this->EscapeQuote(s($req_path));
                 break;
             case "%IP%":
                 $out .= $this->EscapeQuote(s($ip));
                 break;
             case "%REQUEST_ID%":
                 $out .= $this->EscapeQuote(s($req_id));
                 break;
             case "%TIME%":
                 $out .= $this->EscapeQuote(s($time));
                 break;
             case "%LEVEL%":
                 $out .= $this->EscapeQuote(s($level));
                 break;
             case "%MESSAGE%":
                 $out .= $this->EscapeQuote(s($message));
                 break;
             case "%FILE%":
                 $out .= $this->EscapeQuote(s($file));
                 break;
             case "%LINE%":
                 $out .= $this->EscapeQuote(s($line));
                 break;
             default:
                 break;
         }
     }
     $out .= $eol;
     $this->write(s($out));
 }