1

我正在尝试使用内置的 Slim 记录器,但到目前为止还没有成功。

这是我正在尝试的,但我得到一个错误。

  1. 更改为 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. 从 index.php 调用日志编写器:

$app->log->debug("这是来自记录器的测试...");

收到错误:

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

1 回答 1

2

为了在闭包 ( configureMode) 中访问变量,您需要将其与use(...)参数列表一起传递:

$app->configureMode('dev', function () use ($app, $public_path, $uri_public_root, $logWriter) {

    $app->config([
        'log.enable' => true,
        'log.writer' => $logWriter,
        'debug' => false,
        ...
});
于 2016-07-26T21:56:58.507 回答