8000 minor #7360 [Console] Document how to exclude messages from output us… · symfony/symfony-docs@5d5f2ff · GitHub
[go: up one dir, main page]

Skip to content

Commit 5d5f2ff

Browse files
committed
minor #7360 [Console] Document how to exclude messages from output using SymfonyStyle (chalasr, javiereguiluz)
This PR was merged into the master branch. Discussion ---------- [Console] Document how to exclude messages from output using SymfonyStyle This adds documentation for symfony/symfony#20586, any suggestion will be really welcomed. Commits ------- a5c5524 Minor fix ff0ccde Reworded the description 31a2a44 Document how to exclude irrelevant messages from command output using SymfonyStyle
2 parents 4780ba4 + a5c5524 commit 5d5f2ff

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

console/style.rst

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,3 +373,35 @@ of your commands to change their appearance::
373373
// ...
374374
}
375375
}
376+
377+
Writing to the error output
378+
---------------------------
379+
380+
If you reuse the output of a command as the input of other commands or dump it
381+
into a file for later reuse, you probably want to exclude progress bars, notes
382+
and other output that provides no real value.
383+
384+
Commands can output information in two different streams: ``stdout`` (standard
385+
output) is the stream where the real contents should be output and ``stderr``
386+
(standard error) is the stream where the errors and the debugging messages
387+
should be output.
388+
389+
The :class:`Symfony\\Component\\Console\\Style\\SymfonyStyle` class provides a
390+
convenient method called :method:`Symfony\\Component\\Console\\Style\\SymfonyStyle::getErrorStyle`
391+
to switch between both streams. This method returns a new ``SymfonyStyle``
392+
instance which makes use of the error output::
393+
394+
$io = new SymfonyStyle($input, $output);
395+
396+
// Write to the standard output
397+
$io->write('Reusable information');
398+
399+
// Write to the error output
400+
$io->getErrorStyle()->warning('Debugging information or errors');
401+
402+
.. note::
403+
404+
If you create a ``SymfonyStyle`` instance with an ``OutputInterface`` object
405+
that is not an instance of :class:`Symfony\\Component\\Console\\Output\\ConsoleOutputInterface`,
406+
the ``getErrorStyle()`` method will have no effect and the returned object
407+
will still write to the standard output instead of the error output.

0 commit comments

Comments
 (0)
0