Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

log as service

i already post this problem but I click on "delete discussion".

The problem is to set the logger as service but with the possibility to use the $dispatcer (getController and getAction) referenced to the class where I get the service log.

Thank you



3.3k
Accepted
answer

This work :)

$di->set("logger", function () use ($config, $di)
        {
            $router = $di->get('router');
            $controller = $router->getControllerName();
            $action = $router->getActionName();
            $logger = new FileAdapter($config->application->logPath);
            $formatter = new LineFormatter("[%date%][Controller: ".$controller."->Action: ".$action."][%type%]{%message%}");
            $logger->setFormatter($formatter);
            return $logger;
        });