facebook twitter hatena line google mixi email

Php/zend framework/zend log

提供: 初心者エンジニアの簡易メモ
移動: 案内検索

ファイルログ例

$path = APPLICATION_PATH . '/../main.log';
$writer = new Zend_Log_Writer_Stream($path);
$writer->addFilter(Zend_Log::DEBUG);
$logger = new Zend_Log($writer);
$logger->debug("hogehoge");

ログトレーサ付

  • IndexController.php
require_once dirname(__FILE__) . '/LogManager.php';
$log = new LogManager();
$log->debug("hogehoge");
  • LogManager.php
class LogManager
{
  private $_logger;
  public function __construct()
  {
    $path = APPLICATION_PATH . '/../main.log';
    $writer = new Zend_Log_Writer_Stream($path);
    $writer->addFilter(Zend_Log::DEBUG);
    $this->_logger = new Zend_Log($writer);
  }
  public function debug($value)
  {
    $headerlog = "";
    $backtraces = debug_backtrace();
    foreach ($backtraces as $key => $trace) {
        $headerlog .= sprintf("#%d %s(%d): %s::%s\n", $key, $trace['file'], $trace['line'], $trace['class'], $trace['function']);
    }
    $this->_logger->debug($headerlog . $value);
  }
}
  • main.txt
2012-02-23T12:24:20+09:00 DEBUG (7): IndexController:logAction:hogehoge