0
点赞
收藏
分享

微信扫一扫

CodeIgniter 打开错误日志


app/config/config.php

/*
|--------------------------------------------------------------------------
| Error Logging Threshold
|--------------------------------------------------------------------------
|
| If you have enabled error logging, you can set an error threshold to
| determine what gets logged. Threshold options are:
| You can enable error logging by setting a threshold over zero. The
| threshold determines what gets logged. Threshold options are:
|
| 0 = Disables logging, Error logging TURNED OFF
| 1 = Error Messages (including PHP errors)
| 2 = Debug Messages
| 3 = Informational Messages
| 4 = All Messages
|
| For a live site you'll usually only enable Errors (1) to be logged otherwise
| your log files will fill up very fast.
|
*/
$config['log_threshold'] = 4;

默认0 不输出log, 4等级最高

app/logs/log-2022-07-29.php

CodeIgniter 打开错误日志_自动补全

输出日志用\log_message函数

log_message('error', "Unable to write cache file: ".$cache_path);

 system/core/Common.php

CodeIgniter 打开错误日志_php_02

 system/libraries/Log.php

/**
* Write Log File
*
* Generally this function will be called using the global log_message() function
*
* @param string the error level
* @param string the error message
* @param bool whether the error is a native PHP error
* @return bool
*/
public function write_log($level = 'error', $msg, $php_error = FALSE)
{
if ($this->_enabled === FALSE)
{
return FALSE;
}

$level = strtoupper($level);

if ( ! isset($this->_levels[$level]) OR ($this->_levels[$level] > $this->_threshold))
{
return FALSE;
}

$filepath = $this->_log_path.'log-'.date('Y-m-d').'.php';
$message = '';

if ( ! file_exists($filepath))
{
$message .= "<"."?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); ?".">\n\n";
}

if ( ! $fp = @fopen($filepath, FOPEN_WRITE_CREATE))
{
return FALSE;
}

$message .= $level.' '.(($level == 'INFO') ? ' -' : '-').' '.date($this->_date_fmt). ' --> '.$msg."\n";

flock($fp, LOCK_EX);
fwrite($fp, $message);
flock($fp, LOCK_UN);
fclose($fp);

@chmod($filepath, FILE_WRITE_MODE);
return TRUE;
}

CodeIgniter phpstorm自动补全

@property \CI_Input input

<?php

/**
* @property \MY_Loader load
* @property \CI_Input input
*/
class Common extends CI_Controller {
// ...
}

举报

相关推荐

0 条评论