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.

How to define the logger class dir

Hi,

I want to use the standard logger class with invo app. The example in the documentation is:

$logger = new \Phalcon\Logger\Adapter\File("app/logs/test.log");

but this is not working, nor is the /../app/logs/test.log path. Logger is working only when I give it the full path to the file.

My question is: is there a way to give to logger a short path?

Thanks

I believe (but might be wrong) that the logger is invoked in many places in an application. Those places can be different folders and an absolute path would take into account of where the file that invokes the logger is.

I believe that there is no way for the logger to accept a short path. In my applications I always use a path that is defined with a ROOTPATH constant which is defined upon startup. ROOTPATH is where all the folders are /app, /library, /var. /public etc. and the path is set with that.

Example: https://github.com/niden/phalcon-angular-harryhogfootball/blob/master/public/index.php https://github.com/niden/phalcon-angular-harryhogfootball/blob/master/app/library/NDN/Bootstrap.php#L323



5.2k
Accepted
answer
edited Oct '14

Thanks for the quick answer! This is a good solution - the root path could even be included in $config.

$config->application->rootDir = dirname(__DIR__)."/";
/**
* App log
 */
$di->set('logger', function() use ($config) {
        // $config->application->logFile is defined in config.ini as "app/logs/app.log"
    return new \Phalcon\Logger\Adapter\File($config->application->rootDir.$config->application->logFile);
});