We are moving our forum in GitHub Discussions. For questions about Phalcon v3/v4 you can visit here and for Phalcon v5 here.

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


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%}");
            return $logger;