Symfony
sponsored by SensioLabs
Menu
  • About
  • Documentation
  • Screencasts
  • Cloud
  • Certification
  • Community
  • Businesses
  • News
  • Download
  1. Home
  2. Documentation
  3. Console
  4. Verbosity Levels
  • Documentation
  • Book
  • Reference
  • Bundles
  • Cloud
Search by Algolia

Verbosity Levels

Edit this page

Warning: You are browsing the documentation for Symfony 2.8, which is no longer maintained.

Read the updated version of this page for Symfony 6.2 (the current stable version).

Verbosity Levels

2.3

The VERBOSITY_VERY_VERBOSE and VERBOSITY_DEBUG constants were introduced in version 2.3

The console has five verbosity levels. These are defined in the OutputInterface:

Value Meaning Console option
OutputInterface::VERBOSITY_QUIET Do not output any messages -q or --quiet
OutputInterface::VERBOSITY_NORMAL The default verbosity level (none)
OutputInterface::VERBOSITY_VERBOSE Increased verbosity of messages -v
OutputInterface::VERBOSITY_VERY_VERBOSE Informative non essential messages -vv
OutputInterface::VERBOSITY_DEBUG Debug messages -vvv

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
// ...
class CreateUserCommand extends Command
{
    // ...

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

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

        // the user class is only printed when the verbose verbosity level is used
        if ($output->getVerbosity() >= OutputInterface::VERBOSITY_VERBOSE) {
            $output->writeln('User class: '.get_class($user));
        }

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

2.8

The ability to pass the verbosity level to the writeln() method was introduced in Symfony 2.8.

There are also more semantic methods you can use to test for each of the verbosity levels:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
if ($output->isQuiet()) {
    // ...
}

if ($output->isVerbose()) {
    // ...
}

if ($output->isVeryVerbose()) {
    // ...
}

if ($output->isDebug()) {
    // ...
}

Note

These semantic methods are defined in the OutputInterface starting from Symfony 3.0. In previous Symfony versions they are defined in the different implementations of the interface (e.g. Output) in order to keep backward compatibility.

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

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.

Tip

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

This work, including the code samples, is licensed under a Creative Commons BY-SA 3.0 license.
We stand with Ukraine.
Version:
Become certified from home

Become certified from home

Symfony Code Performance Profiling

Symfony Code Performance Profiling

↓ Our footer now uses the colors of the Ukrainian flag because Symfony stands with the people of Ukraine.

Avatar of Radosław Kowalewski, a Symfony contributor

Thanks Radosław Kowalewski for being a Symfony contributor

2 commits • 28 lines changed

View all contributors that help us make Symfony

Become a Symfony contributor

Be an active part of the community and contribute ideas, code and bug fixes. Both experts and newcomers are welcome.

Learn how to contribute

Symfony™ is a trademark of Symfony SAS. All rights reserved.

  • What is Symfony?
    • Symfony at a Glance
    • Symfony Components
    • Case Studies
    • Symfony Releases
    • Security Policy
    • Logo & Screenshots
    • Trademark & Licenses
    • symfony1 Legacy
  • Learn Symfony
    • Symfony Docs
    • Symfony Book
    • Reference
    • Bundles
    • Best Practices
    • Training
    • eLearning Platform
    • Certification
  • Screencasts
    • Learn Symfony
    • Learn PHP
    • Learn JavaScript
    • Learn Drupal
    • Learn RESTful APIs
  • Community
    • SymfonyConnect
    • Support
    • How to be Involved
    • Code of Conduct
    • Events & Meetups
    • Projects using Symfony
    • Downloads Stats
    • Contributors
    • Backers
  • Blog
    • Events & Meetups
    • A week of symfony
    • Case studies
    • Cloud
    • Community
    • Conferences
    • Diversity
    • Documentation
    • Living on the edge
    • Releases
    • Security Advisories
    • SymfonyInsight
    • Twig
    • SensioLabs
  • Services
    • SensioLabs services
    • Train developers
    • Manage your project quality
    • Improve your project performance
    • Host Symfony projects
    Deployed on
Follow Symfony
Search by Algolia