LoginSignup
9
9

More than 5 years have passed since last update.

【CakePHP】独自ログ

Last updated at Posted at 2014-04-16

Cakeを使った独自ログの出力方法。

ログ定義

ログ定義は、CakeLogが読み込まれていればどこに定義してもよいが、通常はConfig/bootstrap.phpの最後にデフォルトのログ定義があるので、その後に記述する。

ログの定義は以下のように行う。

ログ定義
CakeLog::config('access_log', array( //ログ定義名
  'engine' => 'FileLog',//出力先。FileLogでファイルに出力するということ。
  'types' => array('access'),//$this->log()の第二引数に渡す値。
  'file' => 'access', //tmp/logs配下に出力されるログ名。拡張子に.logが付く。
));

ログ出力

ログ定義のtypeを指定して出力する。typeが複数のログ定義に存在すれば、それらに出力される。

ログ出力
$this->log('ログ内容', 'access');
出力結果
2014-04-16 11:51:28 access: ログ内容

参考:CakePHP 2でオリジナルログを吐き出す方法

9
9
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
9
9