我是php及其框架的新手。我遵循了有关如何在Logger.php中添加ChromeLogger的官方指南。我还为Chrome Logger添加了chrome扩展程序。
如何查看控制器上的任何日志记录信息?
记录器.php
<?php
namespace Config;
use CodeIgniterConfigBaseConfig;
class Logger extends BaseConfig
{
...
public $handlers = [
//--------------------------------------------------------------------
// File Handler
//--------------------------------------------------------------------
'CodeIgniterLogHandlersFileHandler' => [
/*
* 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.
*/
'CodeIgniterLogHandlersChromeLoggerHandler' => [
/*
* The log levels that this handler will handle.
*/
'handles' => [
'critical', 'alert', 'emergency', 'debug',
'error', 'info', 'notice', 'warning'
],
]
];
}
新闻.php
<?php
namespace AppControllers;
use AppModelsNewsModel;
use CodeIgniterController;
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-Data:...
应该包括在内。
第三,看起来原始的ChromeLogger扩展程序在Chrome中不起作用,但在Firefox中运行良好。日志消息应位于开发工具控制台中。
我安装了这个扩展程序:
服务器日志 作者:拉斯穆斯·舒尔茨
它的工作原理是在新的开发工具选项卡"服务器日志"中添加日志信息。 它还支持新的日志标头X-ServerLog-Location。