Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
QueryLogEnableCommand.php
Go to the documentation of this file.
1 <?php
8 
10 use Symfony\Component\Console\Command\Command;
11 use Symfony\Component\Console\Input\InputInterface;
12 use Symfony\Component\Console\Input\InputOption;
13 use Symfony\Component\Console\Output\OutputInterface;
16 
17 class QueryLogEnableCommand extends Command
18 {
22  const INPUT_ARG_LOG_ALL_QUERIES = 'include-all-queries';
23 
27  const INPUT_ARG_LOG_QUERY_TIME = 'query-time-threshold';
28 
32  const INPUT_ARG_LOG_CALL_STACK = 'include-call-stack';
33 
37  const COMMAND_NAME = 'dev:query-log:enable';
38 
42  const SUCCESS_MESSAGE = "DB query logging enabled.";
43 
47  private $deployConfigWriter;
48 
54  public function __construct(
55  Writer $deployConfigWriter,
56  $name = null
57  ) {
58  parent::__construct($name);
59  $this->deployConfigWriter = $deployConfigWriter;
60  }
61 
65  protected function configure()
66  {
67  $this->setName(self::COMMAND_NAME)
68  ->setDescription('Enable DB query logging')
69  ->setDefinition(
70  [
71  new InputOption(
72  self::INPUT_ARG_LOG_ALL_QUERIES,
73  null,
74  InputOption::VALUE_OPTIONAL,
75  'Log all queries. [true|false]',
76  "true"
77  ),
78  new InputOption(
79  self::INPUT_ARG_LOG_QUERY_TIME,
80  null,
81  InputOption::VALUE_OPTIONAL,
82  'Query time thresholds.',
83  "0.001"
84  ),
85  new InputOption(
86  self::INPUT_ARG_LOG_CALL_STACK,
87  null,
88  InputOption::VALUE_OPTIONAL,
89  'Include call stack. [true|false]',
90  "true"
91  ),
92  ]
93  );
94 
95  parent::configure();
96  }
97 
102  protected function execute(InputInterface $input, OutputInterface $output)
103  {
105 
106  $logAllQueries = $input->getOption(self::INPUT_ARG_LOG_ALL_QUERIES);
107  $logQueryTime = $input->getOption(self::INPUT_ARG_LOG_QUERY_TIME);
108  $logCallStack = $input->getOption(self::INPUT_ARG_LOG_CALL_STACK);
109 
110  $data[LoggerProxy::PARAM_LOG_ALL] = (int)($logAllQueries != 'false');
111  $data[LoggerProxy::PARAM_QUERY_TIME] = number_format($logQueryTime, 3);
112  $data[LoggerProxy::PARAM_CALL_STACK] = (int)($logCallStack != 'false');
113 
114  $configGroup[LoggerProxy::CONF_GROUP_NAME] = $data;
115 
116  $this->deployConfigWriter->saveConfig([ConfigFilePool::APP_ENV => $configGroup]);
117 
118  $output->writeln("<info>". self::SUCCESS_MESSAGE . "</info>");
119  }
120 }
execute(InputInterface $input, OutputInterface $output)
if(!isset($_GET['name'])) $name
Definition: log.php:14