I created a custom command. I want to log with monolog the command tapped by user with arguments and options
For exemple: php bin/console app:my_command argument1 --option=1234
Now I have that :
$this->log->error('error on command', array(
'command_tapped_by_user' => '????',
'command' => $this->getName(),
'arguments' => $input->getArguments(),
'options' => $input->getOptions(),
'exception' => $e->getMessage()
));
Thank you
All arguments passed to the PHP script are available in the
$argv
array, where first element is a script name. It is not a "superglobal" array and in the Symfony command (or in any other function or method) it available as element of$GLOBALS
or through theglobal
keyword. Original command is splitted by whitespace characters. To restore it you should join them back:Also if you are not worry about OS dependencies (and if you are a nonconformist), you can use system facilities. For example in the Linux environment current command line is stored in the
/proc/$PID/cmdline
: