slimuserfrosting

Enabling logwriter in Userfrosting


I'm trying to use the built-in Slim logwriter, but not successful so far.

This is what I'm trying, but I get an error.

  1. Change to config_userfrosting.php:

    /*Create a log writer */
    
    $logWriter = new \UserFrosting\LogWriter(fopen('C:\xampp\htdocs\userfrosting\log\dev_logfile.log', 'a'));
    
    $app->configureMode('dev', function () use ($app, $public_path, $uri_public_root) {
    $app->config([
        'log.enable' => true,
        'log.writer' => $logWriter,
        'debug' => false,
    
  2. Call Log writer from index.php:

$app->log->debug("This is a test from the logger...");

Error received:

  PHP Notice:  Undefined variable: logWriter in \\userfrosting\\config-userfrosting.php on line 33

Solution

  • In order for a variable to be accessed inside your closure (configureMode), you need to pass it in with the list of use(...) arguments:

    $app->configureMode('dev', function () use ($app, $public_path, $uri_public_root, $logWriter) {
    
        $app->config([
            'log.enable' => true,
            'log.writer' => $logWriter,
            'debug' => false,
            ...
    });