LoginSignup
0
0

[baserCMS]5系で4系と同じ任意のログファイル出力を設定する

Last updated at Posted at 2024-06-06

baserCMS5系で、任意のログファイルを出力する仕組みの紹介です。
たとえば、プラグインで設定するときはこのようにすると良いです。

  • plugins/Example/config/setting.php
use Cake\Log\Engine\FileLog;
use Cake\Log\Log;


if (!defined('LOG_EXAMPLE')) {
	define('LOG_EXAMPLE', 'log_example');
	Log::setConfig('log_example', [
		'className' => FileLog::class,
		'path' => LOGS,
		'scopes' => ['log_example'],
		'levels' => ['info'],
		'file' => 'log_example',
		'rotate' => 5, // 未指定の場合は10
		'size' => 10485760, // 未指定の場合は10485760の10MB
	]);
}

この設定をすることで、以下に出力されます。
logs/log_example.log

環境

  • PHP 8.1.5
  • baserCMS 5.0.15

ちょっと注意する点

setting.php では設定値を return するので、その前(上)に記述すること。

// この上に記述
return [
    'BcApp' => [
        // Add your plugin's configuration here
    ]
];

参考

0
0
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
0
0