Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create new CLI command: Enable DB logging #9200

Closed
vrann opened this issue Apr 11, 2017 · 6 comments
Closed

Create new CLI command: Enable DB logging #9200

vrann opened this issue Apr 11, 2017 · 6 comments
Assignees
Labels
Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development up for grabs

Comments

@vrann
Copy link
Contributor

vrann commented Apr 11, 2017

In order to help developers to work with the Magento, create new commands which will simplify the debugging of the application. Currently, enabling of these setting require doing that either with the UI or changing the configuration of the di.xml.

Create CLI command which will make possible to enable/disable DB query logging

@ClodClod
Copy link

I think could be very useful

@vrann
Copy link
Contributor Author

vrann commented Apr 11, 2017

@federivo volunteered for this contribution.
I would assume the command will be implemented in \Mageno\Developer module. As an example of unit tests for such command, you can check tests in the following directory: app/code/Magento/Developer/Test/Unit/Console/Command

@federivo
Copy link
Member

Great @vrann , thank you.
I'll briefly describe my thoughts on how to implement in a bit.

@federivo
Copy link
Member

Hey @vrann

I would love your feedback on these.

  • Enable SQL queries logging command:

I see this one as a setting in the core_config_data table as much as the "dev/debug/template_hints_storefront" setting for template hints.
So the command should set that setting as true or false depending on current value and we'll need to check for that value in the getStats method in Magento\Framework\DB\Logger\LoggerAbstract in order to return the log data or an empty string.

One thing to consider is that the user will still need to change the preference for the dependency. In my point of view, if the command somehow set which implementation of the DB logger to use it will override the user preference who may be using Magento\Framework\DB\Logger\File or his own implementation. So the user should set the preference for the logger and then can enable and disable it by using the command.
Maybe we can check if the preference set in the di.xml is Magento\Framework\DB\Logger\Quiet and send a warning to the user?

Thoughts?

  • Enable / disable template hints:

This should change the setting "dev/debug/template_hints_storefront" in the core_config_data table. Set to true if it is false and viceversa.

  • Enable / disable magento profiler:

I'm in doubt with this one. Should this enable / disable the outcome of this: http://devdocs.magento.com/guides/v2.1/config-guide/db-profiler/db-profiler.html ?

Thanks!

@vrann
Copy link
Contributor Author

vrann commented Apr 13, 2017

@federivo Hi, can you join the slack team https://magentocommeng.slack.com/, I created the room to discuss this work.

Let's attack the first issue: query logging.
There are two problems which I see

  • there is no way dynamically change DI configuration by the CLI command.
  • the configuration for the query logging cannot really be stored in the database because you need it before the classes used to perform database connection are created

However, Magento has a mechanism to pass the configuration to the DI from the app/etc/env.php file. As far as you know, this file contains deployment information for the Magento and should exist prior doing database connections.

As a reference on how to pass parameters to the DI, you can check app/etc/di.xml:254 where Magento\Framework\App\State object is configured with the MAGE_MODE configuration written to the env.php

For the sake of query logging you can do following:

  1. create the new class which implements LoggerInterface. It should not do logging by itself but act as a Proxy to the actual Logger. Let's call it LoggerProxy
  2. LoggerProxy should accept the alias of the actual Logger, such as "quiet" or "file" through the parameter of the constructor.
  3. configure DI in the way that the alias of actual Logger passed to the LoggerProxy is taken from the env.php. It will be something like
<argument name="loggerName" xsi:type="init_parameter">\Magento\Framework\DB\LoggerProxy::PARAM_NAME</argument>
  1. Change the preference of the logger in app/etc/di.xml:105 from Quiet to LoggerProxy
  2. Implement LoggerProxy in the way that it instantiates the Logger based on the passed alias with desired parameters. Then all calls to the public methods are proxied to the instance of actual logger.
  3. CLI command now should change the env.php file and add configuration of the Logger alias. To see how it can be done check implementation of the setup/src/Magento/Setup/Console/Command/ConfigSetCommand.php

@vrann vrann changed the title Create new CLI command: Enable dev settings, i.e DB logging, Profiler, Template Hints Create new CLI command: Enable DB logging Apr 17, 2017
@magento-team magento-team added Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development Dev Tools up for grabs labels Jul 31, 2017
@magento-team
Copy link
Contributor

Internal ticket to track issue progress: MAGETWO-67501

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development up for grabs
Projects
None yet
Development

No branches or pull requests

5 participants