Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/248.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何将CI REST API日志保存到txt文件_Php_Rest_Api_Continuous Integration - Fatal编程技术网

Php 如何将CI REST API日志保存到txt文件

Php 如何将CI REST API日志保存到txt文件,php,rest,api,continuous-integration,Php,Rest,Api,Continuous Integration,im新手,并混淆如何从日志CI Rest API获取值以保存到Txt文件。这些库已保存到db中,但我无法获取创建变量和保存到文件的值。对不起,英语不好,请帮忙 代码如下: protected function _log_request($authorized = FALSE) { // Insert the request into the log table $is_inserted = $this->rest->db->insert( $th

im新手,并混淆如何从日志CI Rest API获取值以保存到Txt文件。这些库已保存到db中,但我无法获取创建变量和保存到文件的值。对不起,英语不好,请帮忙

代码如下:

protected function _log_request($authorized = FALSE)
{
    // Insert the request into the log table
    $is_inserted = $this->rest->db->insert(
        $this->config->item('rest_logs_table'), [
            'uri' => $this->uri->uri_string(),
            'method' => $this->request->method,
            'params' => $this->_args ? ($this->config->item('rest_logs_json_params') === TRUE ? json_encode($this->_args) : serialize($this->_args)) : NULL,
            'api_key' => isset($this->rest->key) ? $this->rest->key : '',
            'ip_address' => $this->input->ip_address(),
            'time' => time(),
            'authorized' => $authorized
        ]);

    //variable for saving value
    $uri        = $this->uri->uri_string();
    $method     = $this->request->method;
    $params     = $this->_args ? ($this->config->item('rest_logs_json_params') === TRUE ? json_encode($this->_args) : serialize($this->_args)) : NULL;
    $api_key    = isset($this->rest->key) ? $this->rest->key : '';
    $ip_address = $this->input->ip_address();
    $time = time();

    //write into file
    $logs = fopen("logs.txt","a");
    fputs($logs, $uri. "\n");
    fputs($logs, $method. "\n");
    fputs($logs, $params. "\n");
    fputs($logs, $api_key. "\n");
    fputs($logs, $ip_address. "\n");
    fputs($logs, $time. "\n");
    fclose($logs);

    // Get the last insert id to update at a later stage of the request
    $this->_insert_id = $this->rest->db->insert_id();       

    return $is_inserted;
}
试试这个

$message="\n\n".str_repeat("=", 100);
$message .= "uri =>".$uri."\n";
$message .= "method=>".$method."\n";
$message .= "params =>".$params."\n";
$message .= "api_key=>".$api_key."\n";
$message .= "ip_address =>".$ip_address."\n";
$message .= "time=>".$time."\n";

$filepath="application/logs/log-".date('Y-m-d').'.txt';
$fp = fopen($filepath, "a")
fwrite($fp, $message);
fclose($fp);
试试这个

$message="\n\n".str_repeat("=", 100);
$message .= "uri =>".$uri."\n";
$message .= "method=>".$method."\n";
$message .= "params =>".$params."\n";
$message .= "api_key=>".$api_key."\n";
$message .= "ip_address =>".$ip_address."\n";
$message .= "time=>".$time."\n";

$filepath="application/logs/log-".date('Y-m-d').'.txt';
$fp = fopen($filepath, "a")
fwrite($fp, $message);
fclose($fp);

您应该使用
错误记录阈值
,编辑
application/config.php

启用日志

$config['log_threshold']=1

您可以将调试消息、信息消息和错误消息存储到日志文件中

0 = Disables logging, Error logging TURNED OFF
1 = Error Messages (including PHP errors)
2 = Debug Messages
3 = Informational Messages
4 = All Messages

您应该使用
错误记录阈值
,编辑
application/config.php

启用日志

$config['log_threshold']=1

您可以将调试消息、信息消息和错误消息存储到日志文件中

0 = Disables logging, Error logging TURNED OFF
1 = Error Messages (including PHP errors)
2 = Debug Messages
3 = Informational Messages
4 = All Messages

存储的唯一数据是$timeIf solution is works,则请标记为正确,然后未来用户轻松找到正确答案存储的唯一数据是$timeIf solution is works,则请标记为正确,然后未来用户轻松找到正确答案