【发布时间】:2016-05-12 05:48:16
【问题描述】:
我有一个服务器,许多 IOS 和 Android 客户端在该服务器上发送 HTTP 请求,并根据该请求向它们发送一些响应。
现在我想将所有传入请求存储在我的日志中,以便有助于调试。我还想存储我的服务器发回的响应。
我在服务器上收到的请求:
$data = $this->license_m->array_from_get(array('request','device_id','product','software_version','platform_os','platform_model','platform'));
响应服务器回馈
$response = array(
'response_code' =>200 ,
'request'=> $this->input->get('request'),
'device_id'=> $this->input->get('device_id'),
'allowed_hours'=> $remaining_hours,
'product'=>'mlc',
'url'=>NULL
);
return $this->output
->set_content_type('Content-Type: application/json')
->set_output(json_encode($response));
现在我想将所有这些数据记录到我的 codeigniter 的日志中。该怎么做?
我试过这个:
log_message('debug',print_r($data,TRUE));
但这会保存请求数组或响应数组,而不是两者都保存
我的执照类别 :
<?php
/**
*
*/
class License extends Admin_Controller
{
public function __construct()
{
parent::__construct();
$this->load->model('license_m');
}
public function index($id = NULl)
{
$req = $this->input->get('request');
if($req =="trial")
{
$request = array(
'request' => $this->input->get('request'),
'device_id' => $this->input->get('device_id'),
'launch_date'=> $this->input->get('launch_date'),
'allowed_hours'=>$this->input->get('trial_usage'),
'product'=>$this->input->get('product'),
'software_version'=> $this->input->get('software_version'),
'platform_os'=> $this->input->get('platform_os'),
'platform'=> $this->input->get('platform'),
'platform_model'=> $this->input->get('platform_model')
);
/* checking if device id exists */
$data = $this->license_m->array_from_get(array('request','device_id','product','software_version','platform_os','platform_model','platform'));
$this->db->where('device_id',$data['device_id']);
$this->db->where('request','activation');
$query = $this->db->get('activation');
$response = array(
'response_code' =>200 ,
'device_id'=> $this->input->get('device_id'),
'expiry_date'=> '20201231-235959',
'product'=>'mlc',
'url'=>NULL ,
'request'=> $this->input->get('request')
);
return $this->output
->set_content_type('Content-Type: application/json')
->set_output(json_encode($response));
【问题讨论】:
-
在codeigniter中使用钩子概念
-
您是否尝试过查看
Apache或nginx日志,这些日志可能已经包含您要查找的信息?apache日志通常位于/var/log/文件夹中。 -
@VairaMuthu 钩子将如何帮助我?
-
@PrahladYeri 但我不希望每个 apache 日志我只想保存一些可用于调试我的应用程序的特定信息
-
@Rajan 我的意思是您的 apache 日志可能已经存储了这些信息,默认情况下,大多数生产服务器上的日志记录是打开的。你试过检查吗?
标签: php codeigniter logging