Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get Symfony log dir from the controller?

Tags:

php

symfony

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 ?

like image 365
Nelson Teixeira Avatar asked Apr 14 '15 13:04

Nelson Teixeira


People also ask

Where is log file in Symfony?

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.

What is a Symfony controller?

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 .


1 Answers

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();
like image 193
Med Avatar answered Sep 23 '22 21:09

Med