Monologを使用してアプリのログ システムを作成しています。コア アプリ ファイルで、新しい Monolog オブジェクトを作成した後、ログ ファイルに出力するログ レベルを選択する必要があります。「DEBUG」、「INFO」などのグローバル定数を使用したいのですLOG_LEVEL
が、Monolog クラスでその値をクラス定数として扱う必要があります。
// content of config.php
// Here I declare the constants in a separate file called 'config.php'
define("LOG_FILE", "patch/to/my/log.log");
define("LOG_LEVEL", "ERROR");
// content of app.php
require 'config.php';
require 'vendor/autoload.php';
$container['logger'] = function($c) {
$logger = new \Monolog\Logger('logger');
error_log('log level ' . LOG_LEVEL); // prints 'log level ERROR'
$fileHandler = new \Monolog\Handler\StreamHandler(LOG_FILE, $logger::LOG_LEVEL); // here I get the error 'Undefined class constant LOG_LEVEL'
//the normal syntax would be '$logger::ERROR' in this case and that works fine
$logger->pushHandler($fileHandler);
return $logger;
};
「LOG_LEVEL」定数を「LOG_LEVEL」としてではなく、モノログ クラスで「ERROR」として使用する必要があります。私はここで何を間違っているのですか、何時間も答えを探していましたが、運がありませんでした。