如何在 Codeigniter 中更改日志文件扩展名

How to change log file extension in Codeigniter

我看过其他关于 Codeigniter 错误记录的帖子 (here),但我的问题有点不同。出于某种原因,我所有的日志文件都被保存为 .php,我找不到导致这种情况发生的代码部分。我在回购协议本身和大量谷歌搜索中进行了相当广泛的搜索,但看不到任何非常不寻常的东西。

提前致谢。

打开文件 /application/config/config.php 并搜索 $config['log_file_extension']。 用您喜欢的扩展名填充空值。

| 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'.

您可以通过application/config/config.php更改它。请找到下面提到的代码并设置您的自定义扩展名。

/*
  |--------------------------------------------------------------------------
  | Log File Extension
  |--------------------------------------------------------------------------
  |
  | 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'.
  |
 */
$config['log_file_extension'] = '';

您还可以根据您的要求生成日志,如下所述。

/*
  |--------------------------------------------------------------------------
  | Error Logging Threshold
  |--------------------------------------------------------------------------
  |
  | 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
  |
  | You can also pass an array with threshold levels to show individual error types
  |
  |     array(2) = Debug Messages, without Error 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'] = 1;

设置自定义目录来保存您的日志文件。

/*
  |--------------------------------------------------------------------------
  | Error Logging Directory Path
  |--------------------------------------------------------------------------
  |
  | Leave this BLANK unless you would like to set something other than the default
  | application/logs/ directory. Use a full server path with trailing slash.
  |
 */
$config['log_path'] = '';

这将用于设置日志文件的权限。

/*
  |--------------------------------------------------------------------------
  | Log File Permissions
  |--------------------------------------------------------------------------
  |
  | 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.)
 */
$config['log_file_permissions'] = 0644;

这将用于设置每个日志条目的日期格式。

/*
  |--------------------------------------------------------------------------
  | Date Format for Logs
  |--------------------------------------------------------------------------
  |
  | Each item that is logged has an associated date. You can use PHP date
  | codes to set your own date formatting
  |
 */
$config['log_date_format'] = 'Y-m-d H:i:s';

希望对您有所帮助。