setLoggers() публичный Метод

Used to enable or disable logging stream output to stdout and stderr If you don't wish all log output in stdout or stderr through Cake's Log class, call this function with $enable=false.
public setLoggers ( integer | boolean $enable ) : void
$enable integer | boolean Use a boolean to enable/toggle all logging. Use one of the verbosity constants (self::VERBOSE, self::QUIET, self::NORMAL) to control logging levels. VERBOSE enables debug logs, NORMAL does not include debug logs, QUIET disables notice, info and debug logs.
Результат void
Пример #1
0
 /**
  * Runs the Shell with the provided argv.
  *
  * Delegates calls to Tasks and resolves methods inside the class. Commands are looked
  * up with the following order:
  *
  * - Method on the shell.
  * - Matching task name.
  * - `main()` method.
  *
  * If a shell implements a `main()` method, all missing method calls will be sent to
  * `main()` with the original method name in the argv.
  *
  * For tasks to be invoked they *must* be exposed as subcommands. If you define any subcommands,
  * you must define all the subcommands your shell needs, whether they be methods on this class
  * or methods on tasks.
  *
  * @param array $argv Array of arguments to run the shell with. This array should be missing the shell name.
  * @param bool $autoMethod Set to true to allow any public method to be called even if it
  *   was not defined as a subcommand. This is used by ShellDispatcher to make building simple shells easy.
  * @return mixed
  * @link http://book.cakephp.org/3.0/en/console-and-shells.html#the-cakephp-console
  */
 public function runCommand($argv, $autoMethod = false)
 {
     $command = isset($argv[0]) ? $argv[0] : null;
     $this->OptionParser = $this->getOptionParser();
     try {
         list($this->params, $this->args) = $this->OptionParser->parse($argv);
     } catch (ConsoleException $e) {
         $this->err('<error>Error: ' . $e->getMessage() . '</error>');
         $this->out($this->OptionParser->help($command));
         return false;
     }
     if (!empty($this->params['quiet'])) {
         $this->_io->level(ConsoleIo::QUIET);
         $this->_io->setLoggers(false);
     }
     if (!empty($this->params['verbose'])) {
         $this->_io->level(ConsoleIo::VERBOSE);
     }
     if (!empty($this->params['plugin'])) {
         Plugin::load($this->params['plugin']);
     }
     $this->command = $command;
     if (!empty($this->params['help'])) {
         return $this->_displayHelp($command);
     }
     $subcommands = $this->OptionParser->subcommands();
     $method = Inflector::camelize($command);
     $isMethod = $this->hasMethod($method);
     if ($isMethod && $autoMethod && count($subcommands) === 0) {
         array_shift($this->args);
         $this->startup();
         return call_user_func_array([$this, $method], $this->args);
     }
     if ($isMethod && isset($subcommands[$command])) {
         $this->startup();
         return call_user_func_array([$this, $method], $this->args);
     }
     if ($this->hasTask($command) && isset($subcommands[$command])) {
         $this->startup();
         array_shift($argv);
         return $this->{$method}->runCommand($argv, false);
     }
     if ($this->hasMethod('main')) {
         $this->startup();
         return call_user_func_array([$this, 'main'], $this->args);
     }
     $this->out($this->OptionParser->help($command));
     return false;
 }
Пример #2
0
 /**
  * Set the output level based on the parameters.
  *
  * This reconfigures both the output level for out()
  * and the configured stdout/stderr logging
  *
  * @return void
  */
 protected function _setOutputLevel()
 {
     $this->_io->setLoggers(ConsoleIo::NORMAL);
     if (!empty($this->params['quiet'])) {
         $this->_io->level(ConsoleIo::QUIET);
         $this->_io->setLoggers(ConsoleIo::QUIET);
     }
     if (!empty($this->params['verbose'])) {
         $this->_io->level(ConsoleIo::VERBOSE);
         $this->_io->setLoggers(ConsoleIo::VERBOSE);
     }
 }
Пример #3
0
 /**
  * For all loaded plugins, add a short alias
  *
  * This permits a plugin which implements a shell of the same name to be accessed
  * Using the shell name alone
  *
  * @return array the resultant list of aliases
  */
 public function addShortPluginAliases()
 {
     $plugins = Plugin::loaded();
     $io = new ConsoleIo();
     $task = new CommandTask($io);
     $io->setLoggers(false);
     $list = $task->getShellList() + ['app' => []];
     $fixed = array_flip($list['app']) + array_flip($list['CORE']);
     $aliases = [];
     foreach ($plugins as $plugin) {
         if (!isset($list[$plugin])) {
             continue;
         }
         foreach ($list[$plugin] as $shell) {
             $aliases += [$shell => $plugin];
         }
     }
     foreach ($aliases as $shell => $plugin) {
         if (isset($fixed[$shell])) {
             Log::write('debug', "command '{$shell}' in plugin '{$plugin}' was not aliased, conflicts with another shell", ['shell-dispatcher']);
             continue;
         }
         $other = static::alias($shell);
         if ($other) {
             $other = $aliases[$shell];
             Log::write('debug', "command '{$shell}' in plugin '{$plugin}' was not aliased, conflicts with '{$other}'", ['shell-dispatcher']);
             continue;
         }
         static::alias($shell, "{$plugin}.{$shell}");
     }
     return static::$_aliases;
 }