php - 无法在 Codeigniter4 中触发 ChromeLogger 处理程序
问题描述
我是 php 及其框架的新手。我遵循了有关如何在 Logger.php 中添加 ChromeLogger的官方指南。我还为Chrome Logger添加了 chrome 扩展。
如何查看控制器上的任何日志记录信息?
记录器.php
<?php
namespace Config;
use CodeIgniter\Config\BaseConfig;
class Logger extends BaseConfig
{
...
public $handlers = [
//--------------------------------------------------------------------
// File Handler
//--------------------------------------------------------------------
'CodeIgniter\Log\Handlers\FileHandler' => [
/*
* The log levels that this handler will handle.
*/
'handles' => [
'critical',
'alert',
'emergency',
'debug',
'error',
'info',
'notice',
'warning',
],
/*
* Leave this BLANK unless you would like to set something other than the default
* writeable/logs/ directory. Use a full getServer path with trailing slash.
*/
'path' => WRITEPATH . 'logs/',
/*
* The default filename extension for log files. The default 'php' allows for
* protecting the log files via basic scripting, when they are to be stored
* under a publicly accessible directory.
*
* Note: Leaving it blank will default to 'php'.
*/
'fileExtension' => 'php',
/*
* The file system permissions to be applied on newly created log files.
*
* IMPORTANT: This MUST be an integer (no quotes) and you MUST use octal
* integer notation (i.e. 0700, 0644, etc.)
*/
'filePermissions' => 0644,
],
/**
* The ChromeLoggerHandler requires the use of the Chrome web browser
* and the ChromeLogger extension. Uncomment this block to use it.
*/
'CodeIgniter\Log\Handlers\ChromeLoggerHandler' => [
/*
* The log levels that this handler will handle.
*/
'handles' => [
'critical', 'alert', 'emergency', 'debug',
'error', 'info', 'notice', 'warning'
],
]
];
}
新闻.php
<?php
namespace App\Controllers;
use App\Models\NewsModel;
use CodeIgniter\Controller;
class News extends Controller
{
public function index()
{
log_message('info', 'News Index page is visited');
$model = new NewsModel();
$data = [
'news' => $model->getNews(),
'title' => 'News archive',
];
echo view('templates/header', $data);
echo view('news/overview', $data);
echo view('templates/footer');
}
}
解决方案
首先在 app\Config\Logger.php 中检查你的阈值:
public $threshold = 4;
出厂默认值为 4,但要记录“信息”级别的消息 $threshold 应该是 7!
其次,您可以在浏览器开发工具(网络 -> 标头 -> 响应)中验证您的服务器是否正在发送 ChromeLogger 数据。标题:
X-ChromeLogger-数据: ...
应包括在内。
第三,看起来原来的 ChromeLogger 扩展在 Chrome 中不起作用,但在 Firefox 中运行良好。日志消息应该在开发工具控制台中。
我安装了这个扩展:
它通过在新的开发工具选项卡“服务器日志”中添加日志信息来工作。它还支持新的日志头X-ServerLog-Location。
推荐阅读
- javascript - 错误:序列化从“/”中的“getStaticProps”返回的“.data[4].description”时出错
- python - UnicodeEncodeError:“charmap”编解码器无法在位置 2 编码字符“\U0001f3ab”:字符映射到
- angular - mat-menu 根据需要出现在左键单击而不是右键单击
- javascript - 忽略属于第三方包的未定义变量
- python - Python中Replace方法的不同结果
- javascript - 如何仅在 React Native 的某些屏幕中隐藏父堆栈导航器标题
- macos - 如何本地化 MacOS 文件夹名称?
- javascript - react-native-dropdown-picker 按条件更改下拉背景颜色
- linux - Rstan - 编译错误 - features.h:没有这样的文件或目录
- python - 'json.decoder.JSONDecodeError: Expecting value' 使用 Python 请求