You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Laravel Telescope日志无法显示排查:日志未存入telescope_entries表

解决Telescope无法收集日志及「Log [telescope] is not defined」错误

问题场景

无法将日志写入telescope_entries表,导致Telescope无法展示日志。调用日志的代码:

Log::channel('telescope')->debug('testing log:', ['variable' => $this->testVar]);

已完成的配置

  1. config/logging.php 中定义的telescope通道:
'telescope' => [
    'driver' => 'monolog',
    'handler' => FingersCrossedHandler::class,
    'level' => 'debug',
],
  1. TelescopeServiceProvider.php 中添加LOG类型过滤:
public function register(): void
{
    Telescope::night();

    $this->hideSensitiveRequestDetails();

    $isLocal = $this->app->environment('local');
           
    Telescope::filter(function (IncomingEntry $entry) use ($isLocal) {
                    
        return $isLocal ||
            $entry->isReportableException() ||
            $entry->isFailedRequest() ||
            $entry->isFailedJob() ||
            $entry->isScheduledTask() ||
            $entry->hasMonitoredTag() ||
            $entry->type === EntryType::LOG;
    });
}

出现的错误

laravel.EMERGENCY: Unable to create configured logger. Using emergency logger. {"exception":"[object] (InvalidArgumentException(code: 0): Log [telescope] is not defined.

问题原因及修复步骤

1. 替换为Telescope专属日志Handler

当前使用的FingersCrossedHandler无法将日志写入telescope_entries表,需替换为Telescope提供的专用处理器。修改config/logging.php中的telescope通道配置:

'telescope' => [
    'driver' => 'monolog',
    'handler' => Laravel\Telescope\LogHandler::class,
    'level' => 'debug',
],

若未导入命名空间,可直接使用完整类名,或在文件顶部添加use Laravel\Telescope\LogHandler;

2. 清除配置缓存

错误提示「Log [telescope] is not defined」大概率是配置缓存未刷新,新通道未被加载。执行命令清除缓存:

php artisan config:clear

3. 确认日志收集权限

已在过滤器中添加EntryType::LOG,需额外确认config/telescope.php中未禁用日志监控(默认开启)。

验证修复

重新调用日志代码,访问Telescope日志页面(/telescope/logs),检查测试日志是否正常显示。

内容的提问来源于stack exchange,提问作者jparty

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.25 07:31:10