Yii::getLogger()->log('This is an info message', Logger::LEVEL_INFO);
try { // some code that may throw an exception } catch (Exception $e) { Yii::getLogger()->log('An error occurred', Logger::LEVEL_WARNING, 'application'); Yii::getLogger()->log($e->getMessage(), Logger::LEVEL_WARNING, 'application'); }
Yii::getLogger()->log('A debug message', Logger::LEVEL_DEBUG, 'application'); Yii::getLogger()->log(['username' => 'johndoe', 'permission' => 'admin'], Logger::LEVEL_DEBUG, 'application');This logs a debug message and an array of data containing a user's username and permission. The Yii getLogger function is a part of the logging package library in Yii, which allows developers to customize and manage how log messages are stored and displayed.