Chuyển đến nội dung chính

Magento Debug Logging

Debug logging
'db_logger' => [
     'output' => 'file',
     'log_everything' => 0,
     'query_time_threshold' => '0.001',
     'include_stacktrace' => 0 
]
By default, Magento writes to the debug log

 (<install_directory>/var/log/debug.log) when it is in default or develop mode, but not when it is in production mode. Use the bin/magento setup:config:set --enable-debug-logging command to change the default value.

As of Magento 2.3.1, you can no longer use the bin/magento config:set dev/debug/debug_logging command to enable or disable debug logging for the current mode.

To enable debug logging

  1. Use the setup:config:set command to enable debug logging for the current mode.

    bin/magento setup:config:set --enable-debug-logging=true
    
  2. Flush the cache.

    bin/magento cache:flush
    

To disable debug logging

  1. Use the setup:config:set command to disable debug logging for the current mode.

    bin/magento setup:config:set --enable-debug-logging=false
    
  2. Flush the cache.

    bin/magento cache:flush
    

Database logging

By default, Magento writes database activity logs to <install_directory>/var/debug/db.log.

To enable database logging

  1. Use the dev:query-log command to enable or disable database logging.

    bin/magento dev:query-log:enable
    
    bin/magento dev:query-log:disable
    
  2. In the production mode, run the command for import configuration, because the bin/magento dev:query-log:disable command adds settings to the app/etc/env.php file:

    bin/magento app:config:import
    
  3. Flush the cache.

    bin/magento cache:flush
    

Cron logging

With the release of version 2.3.1, Magento now creates a separate cron log.
Magento recently made cron logging more verbose, which provided more information but lengthened the system.log considerably. Moving cron info to a dedicated log makes both logs easier to read.

By default, Magento writes cron info to <install_directory>/var/log/cron.log.

Syslog logging

By default, Magento writes syslog logs to the operating system syslog file. As of Magento 2.3.1, you must use the magento command to enable or disable the syslog. The setting in the Admin has been removed.

To enable syslog logging

Logging to syslog is disabled by default.

  1. Use the setup:config:set command to change the dev/syslog/syslog_logging database value to true.

    bin/magento setup:config:set --enable-syslog-logging=true
    
  2. Flush the cache.

    bin/magento cache:flush
    

To disable syslog logging

  1. Use the setup:config:set command to change the dev/syslog/syslog_logging database value to false.

    bin/magento setup:config:set --enable-syslog-logging=false
    
  2. Flush the cache.

    bin/magento cache:flush
    

Magento provides a built-in logging system called "Magento Debug Logger" that helps developers debug and troubleshoot issues in their Magento applications. The debug logger is part of the Magento framework and allows you to log specific messages or events during runtime.

To use the Magento Debug Logger, you need to follow these steps:

  1. Enable Developer Mode: Before you can start using the debug logger, make sure your Magento application is running in Developer Mode. You can set the mode by running the following command from your Magento root directory:

    bash
    bin/magento deploy:mode:set developer
  2. Inject the Logger: In the class or script where you want to log debug messages, you need to inject the \Psr\Log\LoggerInterface class. You can do this by adding it as a dependency in the constructor or using dependency injection.

    php
    protected $logger; public function __construct( \Psr\Log\LoggerInterface $logger ) { $this->logger = $logger; }
  3. Log Debug Messages: Once the logger is injected, you can use it to log debug messages throughout your codebase. The logger provides various logging levels such as debug, info, notice, warning, error, critical, and alert.

    php
    $this->logger->debug('This is a debug message.'); $this->logger->info('This is an info message.'); $this->logger->error('This is an error message.');

    You can use the appropriate logging level based on the severity of the message you want to log.

  4. View Logs: The logs generated by the Magento Debug Logger are stored in the var/log directory of your Magento installation. You can access these logs and review them to analyze any issues or debug information.

    shell
    cd /path/to/magento/var/log/ ls -la

    You'll find log files with names like system.log, exception.log, or debug.log, depending on the type of logs you're interested in.

By leveraging the Magento Debug Logger, you can easily trace the execution flow of your application, identify errors, and gather valuable information for troubleshooting purposes.

Nhận xét

Bài đăng phổ biến từ blog này

Magento2 Cheat Sheet

Magento 2 tutorial http://devdocs.magento.com/guides/v2.1/frontend-dev-guide/bk-frontend-dev-guide.html https://www.creare.co.uk/blog/magento/theming-in-magento-2-part-1 https://www.creare.co.uk/blog/magento/theming-in-magento-2-part-2 http://alanstorm.com/category/magento-2/

Google Chrome cheat sheet - Keyboard shortcuts

Windows and Linux Tab and window shortcuts Shortcut Action Alt+F   or   Alt+E   or F10 Opens the Chrome menu   , which lets you customize and control settings in Google Chrome. Ctrl+Shift+B Toggles the bookmarks bar on and off. Ctrl+H Opens the History page. Ctrl+J Opens the Downloads page. Shift+Esc Opens the Task Manager. Shift+Alt+T Sets focus on the first tool in the browser toolbar. You can then use the following shortcuts to move around in the toolbar: ·          Press   Tab, Shift+Tab, Home, End, right arrow,   and   left arrow   to move focus to different items in the toolbar. ·          Press   Space   or   Enter   to activate toolbar buttons, including page actions and browser actions. ·     ...

Magento 2 Bookmark Events

Tổng hợp events có trong magento ,  tạo thêm event bao nhiêu tuỳ thích theo link sau Events and observers