LoginSignup
5
6

More than 5 years have passed since last update.

CakePHPでログの振り分け(1つのconfigで複数ファイルに)

Posted at

概要

CakePHPのロギング設定で、
bootstrap.phpに書くCakeLog::config()は1つにして
吐き出すファイルを分ける方法です。

実装

bootstrap.php
CakeLog::config('sample', array(
    'engine' => 'File',
    'types' => array('jojo', 'dio', 'nukesaku')
));
TestController.php
$this->log('オラオラ', 'jojo');
$this->log('無駄無駄', 'dio');
$this->log('ヌケサク', 'nukesaku');

上記の実装で、1つのconfig設定でログファイルがそれぞれ

  • jojo.log
  • dio.log
  • nukesaku.log

に格納されました。

ポイントは configのfilesを指定しないこと!!
filesを指定しない場合、type名.logというファイル名で
ログが吐き出されることになります。

filesさえ指定しなければ、他のpath等のパラメータは
任意で指定できます。

ただし、filesによるログローテーションができないので
注意してください。

詳しい解説

http://book.cakephp.org/2.0/en/core-libraries/logging.html
http://api.cakephp.org/2.5/class-CakeLog.html
↑公式リファレンス(英語)

5
6
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
5
6