link-in - רשומות קוד

חפש את הקוד שלך >

Logger

בנייה של קונסטרקטור

1: משיכת הקלאס

use Psr\Log\LoggerInterface;

2. הצהרה על המשתנה

    /**
     * @var LoggerInterface
     */
    protected $logger;

3.שילוב בקונסטרקטור

    public function __construct(
        Context $context,
        PageFactory $resultPageFactory,
        CustomerImport $customerImport,
        LoggerInterface $logger,
        Cron $cronExecute
    )
    {
        parent::__construct($context);
        $this->resultPageFactory = $resultPageFactory;
        $this->logger = $logger;
        $this->customerImport = $customerImport;
        $this->cronExecute = $cronExecute;
    }

מימוש בפונקציה

 $this->logger->error('Customer Logged In, Customer Email: '.$customerEmail);

יוצג ב: public_html/var/log/system.log

שימוש בOBJECT MANAGER - למימוש זמני

שימוש בקונסטרקטור

        \Magento\Framework\App\ObjectManager::getInstance()
            ->get(\Psr\Log\LoggerInterface::class)->error('v32423');