How can I get current log file on a Symfony's controller ?
I know I could do it this way:
$logFile = $this->container->getParameter('kernel.root_dir') . "/logs/" .
$this->container->get('kernel')->getEnvironment() . ".log";
but this fails if the log dir is customized. So I thought there should be a more direct way of getting it. Is there is some parameter that holds the current log file ?
A related question: where can I get the list of all container parameters ?
In addition to the standard PHP logs, symfony can log a lot of custom events. You can find all the symfony logs under the myproject/log/ directory. There is one file per application and per environment. For instance, the development environment log file of the myapp application is named myapp_dev.
In Symfony, a controller is usually a class method which is used to accept requests, and return a Response object. When mapped with a URL, a controller becomes accessible and its response can be viewed. To facilitate the development of controllers, Symfony provides an AbstractController .
For a list of parameters, use the symfony console:
For symfony 2.6 ( maybe 2.7)
app/console debug:container --parameters
For 2.3
app/console container:debug --parameters
EDIT FOR THE LOG DIR
The log dir is stored in kernel parameters. You can access like this:
$container->get('kernel')->getLogDir();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With