1

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
accord_guy
  • 314
  • 2
  • 11

1 Answers1

2

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,
        ...
});
alexw
  • 8,468
  • 6
  • 54
  • 86
  • I updated the use(..) arguments as shown. However, now getting the following error: `PHP Fatal error: Class 'UserFrosting\\LogWriter' not found in C:\\xampp\\htdocs\\userfrosting\\config-userfrosting.php` – accord_guy Jul 27 '16 at 12:58
  • Got it. I needed to use \Slim\Logwriter instead. Thanks @alexw. – accord_guy Jul 27 '16 at 13:40