I am new to symfony.
I am trying to change the formatting of the output Monolog file using the console argument 'format = json'.
In short, I want to run any console command as follows:
app/console my_command --format=json
... and get the result of the LoggerInterface in the requested format.
For example, I set the default formatter in the configuration:
monolog:
handlers:
console:
type: console
channels: [!event, !doctrine]
formatter: json_formatter
services:
json_formatter:
class: Monolog\Formatter\JsonFormatter
When I create some MyEventListener :: onConsoleCommand ( as described here ), I cannot change the parameter package because it is already compiled: It is not possible to call set () on a frozen ParameterBag. "
Up2: My services configuration in this case is as follows:
services:
kernel.listener.command_dispatch:
class: My\Listener\MyEventListener
autowire: true
tags:
- { name: kernel.event_listener, event: console.command }
On the other hand, I can register the console option in the source file:
$loader = require __DIR__.'/autoload.php';
$application->getDefinition()->addOption(
new InputOption(
'formatter',
'f',
InputOption::VALUE_OPTIONAL,
'The logs output formatter',
'json_formatter'
)
);
. $application- > getKernel() → getContainer() - .
, Symfony2 ?
, , ? YAML?
.
UP3:
, :
SYMFONY__LOG__FORMATTER=json_formatter app/console my_command
monolog:
handlers:
console:
type: console
formatter: '%log.formatter%'