Verbosity Levels

Console commands have different verbosity levels, which determine the messages displayed in their output. By default, commands display only the most useful messages, but you can control their verbosity with the -q and -v options:

コンソール コマンドにはさまざまな詳細レベルがあり、出力に表示されるメッセージが決まります。デフォルトでは、コマンドは最も有用なメッセージのみを表示しますが、-q および -v オプションを使用して冗長性を制御できます。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# do not output any message (not even the command result messages)
$ php bin/console some-command -q
$ php bin/console some-command --quiet

# normal behavior, no option required (display only the useful messages)
$ php bin/console some-command

# increase verbosity of messages
$ php bin/console some-command -v

# display also the informative non essential messages
$ php bin/console some-command -vv

# display all messages (useful to debug errors)
$ php bin/console some-command -vvv

The verbosity level can also be controlled globally for all commands with the SHELL_VERBOSITY environment variable (the -q and -v options still have more precedence over the value of SHELL_VERBOSITY):

詳細レベルは、SHELL_VERBOSITY 環境変数を使用してすべてのコマンドに対してグローバルに制御することもできます (-q および -v オプションは、引き続き SHELL_VERBOSITY の値よりも優先されます)。
Console option SHELL_VERBOSITY value Equivalent PHP constant
-q or --quiet -1 OutputInterface::VERBOSITY_QUIET
(none) 0 OutputInterface::VERBOSITY_NORMAL
-v 1 OutputInterface::VERBOSITY_VERBOSE
-vv 2 OutputInterface::VERBOSITY_VERY_VERBOSE
-vvv 3 OutputInterface::VERBOSITY_DEBUG

It is possible to print a message in a command for only a specific verbosity level. For example:

特定の詳細レベルのみのコマンドでメッセージを出力することができます。例えば:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
// ...
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

class CreateUserCommand extends Command
{
    // ...

    public function execute(InputInterface $input, OutputInterface $output): int
    {
        $user = new User(...);

        $output->writeln([
            'Username: '.$input->getArgument('username'),
            'Password: '.$input->getArgument('password'),
        ]);

        // available methods: ->isQuiet(), ->isVerbose(), ->isVeryVerbose(), ->isDebug()
        if ($output->isVerbose()) {
            $output->writeln('User class: '.get_class($user));
        }

        // alternatively you can pass the verbosity level PHP constant to writeln()
        $output->writeln(
            'Will only be printed in verbose mode or higher',
            OutputInterface::VERBOSITY_VERBOSE
        );

        return 0;
    }
}

When the quiet level is used, all output is suppressed as the default write() method returns without actually printing.

quiet レベルが使用されると、defaultwrite() メソッドが実際に印刷せずに戻るため、すべての出力が抑制されます。

Tip

ヒント

The MonologBridge provides a ConsoleHandler class that allows you to display messages on the console. This is cleaner than wrapping your output calls in conditions. For an example use in the Symfony Framework, see How to Configure Monolog to Display Console Messages.

MonologBridge は、コンソールにメッセージを表示できる ConsoleHandler クラスを提供します。これは、条件で出力呼び出しをラップするよりもクリーンです。 Symfony フレームワークでの使用例については、コンソール メッセージを表示するように Monolog を構成する方法を参照してください。

Tip

ヒント

The full exception stacktrace is printed if the VERBOSITY_VERBOSE level or above is used.

VERBOSITY_VERBOSE レベル以上が使用されている場合、完全な例外スタック トレースが出力されます。