我目前正在探索Laraval9自定义日志(https://laravel.com/docs/9.x/logging)
Route::get('/', function () {
// return view('welcome');
Log::channel('abuse')->info('API endpoint abuse', [
'user_id' => 2
]);
});
在我的logging.php中,我还在logging.php内部的顶部定义了"use \Logging\SimpleFor事宜“:
在我的SimpleFormatter类中:
但是,当我触发日志时,会出现一个错误:
[2022-11-18 09:02:31] laravel.EMERGENCY: Unable to create configured logger. Using emergency logger. {"exception":"[object] (Illuminate\\Contracts\\Container\\BindingResolutionException(code: 0): Target class [App\\Logging\\SimpleFormatter] does not exist. at /Users/Shared/laravel-sanctum-api/vendor/laravel/framework/src/Illuminate/Container/Container.php:877)
[stacktrace]
我按照步骤100%执行,但是这个错误一直在弹出。请给出如何处理这个问题的建议。
解决方案:确保在使用该类时检查类目录是否正确。
发布于 2022-11-18 09:42:18
在我的logging.php中,我也在logging.php的顶部定义了"use \Logging\SimpleFor事宜“
您不必这样做,只需保留use App\Logging\SimpleFormatter;
,在您的配置中,只需将tap值设置为:
'tap' => [SimpleFormatter::class],
此外,在这些更改之后尝试运行一个composer dump-autoload
。
https://stackoverflow.com/questions/74487353
复制相似问题