CakePHPのログ出力($this->log) : CakePHP

Pocket

CakePHPで$this->logを使いログを出力するメモ。

$this->logの設定はConfig/bootstrapに記載されている。下記はデフォルトの記載。

/**
 * Configures default file logging options
 */
App::uses('CakeLog', 'Log');
CakeLog::config('debug', array(
    'engine' => 'File',
    'types' => array('notice', 'info', 'debug'),
    'file' => 'debug',
));

Controller

App::uses('CakeLog', 'Log');

class SamplesController {
    public function some() {
        $this->log(['one', 'two', 'three'], 'debug');
    }
}

ログファイル

デフォルトではtmp/logs/debug.logへ出力される。

2015-02-24 00:44:13 Debug: Array
(
    [0] => one
    [1] => two
    [2] => three
)

CakePHP 2でオリジナルログを吐き出す方法 | アイビースター

またPHPは標準関数error_logで特定のディレクトリへログを出力できる。
PHP: error_log – Manual

(例) テストという文字列を/var/tmp/log/log.txtファイルへ追記

error_log('テスト', 3, '/var/tmp/log/log.txt' );

第2引数の3は第3引数で指定されたファイルへ出力することを指定している。

コメント

No comments yet.

コメントの投稿

改行と段落タグは自動で挿入されます。
メールアドレスは表示されません。